Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # ultranary_for_ai.py
- base = 2
- digits = []
- length = 0
- combo_to_next = {}
- def init_combo(n):
- global base, digits, length
- length = n
- base = 2
- digits = [0]*n
- def inc():
- global base, digits
- i = length-1
- while i >= 0:
- digits[i] += 1
- if digits[i] < base:
- return
- digits[i] = 0
- i -= 1
- base += 1
- digits = [0]*length
- def valid():
- return base == 2 or (base-1) in digits
- def get_next():
- while True:
- if valid():
- cur = digits.copy()
- inc()
- while not valid():
- inc()
- combo_to_next[tuple(cur)] = digits.copy()
- return cur
- inc()
- init_combo(3)
- print("Sample combinations:")
- for i in range(100):
- print(i+1, get_next())
- q = (3,3,3)
- print("\nIndex of", q, ":", combo_to_next.get(q))
Advertisement
Add Comment
Please, Sign In to add comment