def generate_combinations(n, max_number): # Initialize the combination combination = [0] * n # Generate all combinations while True: # Print the current combination print(combination) # Increment the combination i = n - 1 while i >= 0: if combination[i] < max_number: combination[i] += 1 break else: combination[i] = 0 i -= 1 # If i < 0, we've exhausted all combinations if i < 0: break if __name__ == '__main__': # Generate all 8-digit combinations generate_combinations(4, 4)