here2share

# ultranary_for_ai.py

Oct 11th, 2025 (edited)
307
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.88 KB | None | 0 0
  1. # ultranary_for_ai.py
  2.  
  3. base = 2
  4. digits = []
  5. length = 0
  6. combo_to_next = {}
  7.  
  8. def init_combo(n):
  9.     global base, digits, length
  10.     length = n
  11.     base = 2
  12.     digits = [0]*n
  13.  
  14. def inc():
  15.     global base, digits
  16.     i = length-1
  17.     while i >= 0:
  18.         digits[i] += 1
  19.         if digits[i] < base:
  20.             return
  21.         digits[i] = 0
  22.         i -= 1
  23.     base += 1
  24.     digits = [0]*length
  25.  
  26. def valid():
  27.     return base == 2 or (base-1) in digits
  28.  
  29. def get_next():
  30.     while True:
  31.         if valid():
  32.             cur = digits.copy()
  33.             inc()
  34.             while not valid():
  35.                 inc()
  36.             combo_to_next[tuple(cur)] = digits.copy()
  37.             return cur
  38.         inc()
  39.  
  40. init_combo(3)
  41.  
  42. print("Sample combinations:")
  43. for i in range(100):
  44.     print(i+1, get_next())
  45.  
  46. q = (3,3,3)
  47. print("\nIndex of", q, ":", combo_to_next.get(q))
Advertisement
Add Comment
Please, Sign In to add comment