Created
March 1, 2013 19:43
-
-
Save thomasballinger/5067194 to your computer and use it in GitHub Desktop.
boggle state transitions for an n x n board
I acknowledge it's a bad idea in the first place, but should I indent this?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def get_transitions(n): | |
"""Return a dictionary of array spots to neighbors for an nxn grid""" | |
return {initial_row*n + initial_col : | |
{row * n + col | |
for row in range(max(0, initial_row-1), min(n, initial_row+2)) | |
for col in range(max(0, initial_col-1), min(n, initial_col+2)) | |
if (row, col) != (initial_row, initial_col)} | |
for initial_row in range(n) | |
for initial_col in range(n)} |
Nice! I was reaching for something like around
, much clearer; thanks!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Unsolicited refactor because I'm distractible: