Advertisement
here2share

# b_base_incr.py

Dec 27th, 2024 (edited)
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.60 KB | None | 0 0
  1. # b_base_incr.py
  2.  
  3. def base_incr(b, base=2, incr=1):
  4.     if tuple(b) in cache:
  5.         return cache[b]
  6.  
  7.     value = 0
  8.     L = len(b)
  9.     for i, num in enumerate(reversed(b)):
  10.         value += num * (base ** i)
  11.     value += incr
  12.     value %= (base ** L)
  13.  
  14.     new_b = []
  15.     for _ in range(L):
  16.         new_b.append(value % base)
  17.         value //= base
  18.  
  19.     result = new_b[::-1]
  20.     cache[tuple(b)] = result
  21.     return result
  22.  
  23. data = [0, 0, 0, 0]
  24. base = 2
  25. cache = {}
  26.  
  27. while data:
  28.     print(''.join(map(str, data)))
  29.     data = base_incr(data, base)
  30.     if data == [0] * 4:
  31.         break
  32.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement