three first days on first try!
This commit is contained in:
22
d03/part1.py
Normal file
22
d03/part1.py
Normal file
@@ -0,0 +1,22 @@
|
||||
import sys
|
||||
|
||||
s = sys.stdin.read()[:-1]
|
||||
|
||||
cp = (0,0)
|
||||
P = {cp}
|
||||
|
||||
dep = {
|
||||
'<':(1,0),
|
||||
'>':(-1,0),
|
||||
'v':(0,1),
|
||||
'^':(0,-1),
|
||||
}
|
||||
|
||||
for c in s:
|
||||
x,y = cp
|
||||
dx,dy = dep[c]
|
||||
cp = (x+dx,y+dy)
|
||||
P.add(cp)
|
||||
|
||||
print(len(P))
|
||||
|
28
d03/part2.py
Normal file
28
d03/part2.py
Normal file
@@ -0,0 +1,28 @@
|
||||
import sys
|
||||
|
||||
s = sys.stdin.read()[:-1]
|
||||
|
||||
cpS = (0,0)
|
||||
cpR = (0,0)
|
||||
P = {cpS}
|
||||
|
||||
dep = {
|
||||
'<':(1,0),
|
||||
'>':(-1,0),
|
||||
'v':(0,1),
|
||||
'^':(0,-1),
|
||||
}
|
||||
|
||||
for i,c in enumerate(s):
|
||||
dx,dy = dep[c]
|
||||
if i%2:
|
||||
x,y = cpS
|
||||
cpS = (x+dx,y+dy)
|
||||
P.add(cpS)
|
||||
else:
|
||||
x,y = cpR
|
||||
cpR = (x+dx,y+dy)
|
||||
P.add(cpR)
|
||||
|
||||
print(len(P))
|
||||
|
Reference in New Issue
Block a user