Created
November 18, 2017 21:10
-
-
Save CarlOlson/9d710daab9401d43599c2c9d6ab2197f to your computer and use it in GitHub Desktop.
Global Day of Coderetreat
This file contains 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
from itertools import product | |
def get_neighbors(coordinate): | |
row = ord(coordinate[0]) | |
col = int(coordinate[1:]) | |
return [ | |
make_coordinate(row + x - 1, col + y - 1) | |
for x, y in product(range(3), range(3)) | |
if (x,y) != (1,1) | |
if row + x - 1 >= ord('A') | |
if col + y - 1 >= 0 | |
if row + x - 1 <= ord('Y') | |
if col + y - 1 <= 24 | |
] | |
def make_coordinate(row, col): | |
return f"{chr(row)}{col}" |
This file contains 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
from main import * | |
class Response: | |
def json(self): | |
return {} | |
def assert_contains(actual, expected): | |
assert len(actual) == len(expected) | |
for x in actual: | |
assert x in expected | |
def test_can_ask_for_neighbors(): | |
neighbors = get_neighbors("A0") | |
assert_contains(neighbors, ["A1", "B0", "B1"]) | |
neighbors = get_neighbors("A24") | |
assert_contains(neighbors, ["A23", "B23", "B24"]) | |
neighbors = get_neighbors("B1") | |
assert_contains(neighbors, ["A0", "A1", "A2", "B0", "B2", "C0", "C1", "C2"]) | |
neighbors = get_neighbors("Y24") | |
assert_contains(neighbors, ["X24", "X23", "Y23"]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment