Created
March 14, 2018 18:04
-
-
Save shiracamus/96ae988eddd5609355b60769538a7b5b to your computer and use it in GitHub Desktop.
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
import time | |
from itertools import count | |
def make_gunegune(size): | |
size = (size + 1) | 1 | |
gunegune = [['-'] * size for y in range(size)] | |
number = count(1) | |
for z in range(1, size, 2): | |
for x in range(1, z, +1): gunegune[z][x] = next(number) | |
for y in range(z, 0, -1): gunegune[y][z] = next(number) | |
z += 1 | |
for y in range(1, z, +1): gunegune[y][z] = next(number) | |
for x in range(z, 0, -1): gunegune[z][x] = next(number) | |
return gunegune | |
def find_pos(gunegune, num): | |
return next((y, x) | |
for y, row in enumerate(gunegune) | |
for x, col in enumerate(row) | |
if col == num) | |
def solve(gunegune, data): | |
y, x = find_pos(gunegune, int(data)) | |
return ','.join(str(gunegune[y + dy][x + dx]) | |
for dy, dx in ((0, -1), (0, 1), (-1, 0), (1, 0))) | |
GUNEGUNE = make_gunegune(size=100) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment