[Python/2017] Move solutions into .py files
This commit is contained in:
parent
fbc5fda60f
commit
7b1efc0d9c
51 changed files with 1100 additions and 4546 deletions
42
Python/2017/11.py
Normal file
42
Python/2017/11.py
Normal file
|
@ -0,0 +1,42 @@
|
|||
from lib import *
|
||||
|
||||
input = read_input(2017, 11).strip()
|
||||
|
||||
|
||||
def step(x, y, d):
|
||||
if d == "n":
|
||||
return x, y - 1 # (0, -1)
|
||||
if d == "ne":
|
||||
return x + 1, y # (1, 0)
|
||||
if d == "se":
|
||||
return x + 1, y + 1 # (1, 1)
|
||||
if d == "s":
|
||||
return x, y + 1 # (0, 1)
|
||||
if d == "sw":
|
||||
return x - 1, y # (-1, 0)
|
||||
if d == "nw":
|
||||
return x - 1, y - 1 # (-1, -1)
|
||||
|
||||
|
||||
x, y = 0, 0
|
||||
for d in input.split(","):
|
||||
x, y = step(x, y, d)
|
||||
k = 0
|
||||
if x * y > 0:
|
||||
k = min(x, y, key=abs)
|
||||
x -= k
|
||||
y -= k
|
||||
print(abs(x) + abs(y) + k)
|
||||
|
||||
|
||||
x, y = 0, 0
|
||||
out = 0
|
||||
for d in input.split(","):
|
||||
x, y = step(x, y, d)
|
||||
k = 0
|
||||
if x * y > 0:
|
||||
k = min(x, y, key=abs)
|
||||
x -= k
|
||||
y -= k
|
||||
out = max(out, abs(x) + abs(y) + k)
|
||||
print(out)
|
Loading…
Add table
Add a link
Reference in a new issue