piRSquared

optimal 4 x 4

Apr 19th, 2021
508
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. def board_maker(rows, cols):
  2.     w = rows * cols
  3.  
  4.     def n2b(n):
  5.         s = f'{bin(n)[2:]:>0{w}}'
  6.         s = s.replace('0', 'M').replace('1', 'B')
  7.         return [list(x) for x in zip(*[iter(s)] * rows)]
  8.    
  9.     def calc(n):
  10.         return calculate_score(n2b(n))
  11.    
  12.     return n2b, calc
  13.  
  14. def iter_neighbors(board, x,y):
  15.     n = len(board)
  16.     m = max(map(len, board))
  17.    
  18.     for dx in (-1,0,1):
  19.         for dy in (-1, 0, 1):
  20.             if dx == dy == 0: continue
  21.             if dy+y < 0 or dy+y >= n or dx+x < 0 or dx+x >= m: continue
  22.             yield board[dy+y][dx+x]
  23.  
  24. n2b, calc = board_maker(4, 4)
  25.  
  26. n = max(range(2 ** 16), key=calc)
  27.  
  28. display(n2b(n))
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×