three first days on first try!

This commit is contained in:
2023-12-01 10:42:13 +01:00
commit ca06c26658
6 changed files with 99 additions and 0 deletions

22
d03/part1.py Normal file
View 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
View 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))