1
0
Fork 0

Puzzle du 11 décembre 2017

This commit is contained in:
Lucidiot 2017-12-11 06:25:19 +01:00
parent b6973711e0
commit e59e8a584f
No known key found for this signature in database
GPG Key ID: 63BD9482C29D0F64
1 changed files with 22 additions and 0 deletions

22
2017/11/hex.py Normal file
View File

@ -0,0 +1,22 @@
#!/usr/bin/env python3
def hex_dist(x, y):
return abs(x) + abs(y)
import sys
directions = {'n': [1, 1],
'nw': [0, 1],
'ne': [1, 0],
's': [-1, -1],
'sw': [-1, 0],
'se': [0, -1]}
data = [directions[k] for k in sys.stdin.readline().strip().split(",")]
x, y, maxd = 0, 0, 0
for d in data:
if hex_dist(x + d[0], y + d[1]) > maxd:
maxd = hex_dist(x + d[0], y + d[1])
x += d[0]
y += d[1]
print(hex_dist(x, y), maxd)