Advertisement
pb_jiang

chomp strategy

Dec 15th, 2024
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.67 KB | None | 0 0
  1. from functools import cache
  2.  
  3. @cache
  4. def search(v: tuple[int]) -> bool:
  5.     if all(x == 0 for x in v[:-1]) and v[-1] == 1:
  6.         return False
  7.     ans = True
  8.     opponent_win = 0
  9.     win_cnt = 0
  10.     for i in range(len(v)):
  11.         for x in range(v[i]):
  12.             nv = tuple(min(x, val) for val in v[:i+1]) + v[i+1:]
  13.             if all(val == 0 for val in nv):
  14.                 continue
  15.             if search(nv):
  16.                 opponent_win += 1
  17.             else:
  18.                 print(f"{v=} => {nv=}")
  19.                 win_cnt += 1
  20.     return win_cnt != 0
  21.  
  22.  
  23. def main():
  24.     v = (7, 7, 7, 7)
  25.     print(f"{search(v)=}")
  26.  
  27. if __name__ == "__main__":
  28.     main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement