Advertisement
Altiumbe

[unfin] Nimber Addition Code

Jun 7th, 2016
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.54 KB | None | 0 0
  1. def nimAdd(a,b):
  2.  
  3.     def nimSieve(a,b):
  4.         return cache(a,b)
  5.  
  6.     cch = dict()
  7.    
  8.     apad = list()
  9.     bpad = list()
  10.     for i in range(a):
  11.         apad.append(nimSieve(i,b))
  12.     for i in range(b):
  13.         bpad.append(nimSieve(a,i))
  14.     return mex(apad + bpad)
  15.  
  16.     def cache(a,b):
  17.         cch = dict()
  18.         try:
  19.             return cch[spell(a,b)]
  20.         except:
  21.             return write(a,b)
  22.  
  23.     def write(a,b):
  24.         cch[spell(a,b)] = nimAdd(a,b)
  25.  
  26.     def spell(a,b):
  27.         return str(a)+","+str(b)
  28.  
  29.     def mex(S):
  30.         for s in range(max(S)+2 if S else 1):
  31.             if s in S:
  32.                 continue
  33.             else:
  34.                 return s
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement