fork download
  1. MAX_SIZE = 9
  2. V = set()
  3.  
  4. def go(positions):
  5. if positions in V:
  6. return
  7.  
  8. V.add(positions)
  9.  
  10. if len(positions) == MAX_SIZE:
  11. return
  12.  
  13. for (x, y) in positions:
  14. for dx, dy in zip([0, -1, 0, +1], [-1, 0, +1, 0]):
  15. nx, ny = x + dx, y + dy
  16. new_positions = list(positions) + [(nx, ny)]
  17. new_positions = tuple(sorted(set(new_positions)))
  18. go(new_positions)
  19.  
  20. go(((0,0),))
  21. print(f"WITH AT MOST {MAX_SIZE} PIECES THERE ARE {len(V)} SETS.")
  22.  
Success #stdin #stdout 2.13s 34688KB
stdin
Standard input is empty
stdout
WITH AT MOST 9 PIECES THERE ARE 118020 SETS.