three first day on first tries!

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

6
d01/part1.py Normal file
View File

@ -0,0 +1,6 @@
import sys
s = sys.stdin.read()[:-1]
print(sum(map(lambda c: [-1,1][c=='('],s)))

10
d01/part2.py Normal file
View File

@ -0,0 +1,10 @@
import sys
s = sys.stdin.read()[:-1]
f = 0
for i,c in enumerate(s):
f += -1 if c == ')' else 1
if f == -1:
print(i+1)
break

17
d02/part1.py Normal file
View File

@ -0,0 +1,17 @@
import sys
def processline(l):
# a x b x c
(a,b,c) = tuple(map(int,l.split('x')))
print(l, a,b,c)
s1 = a * b
s2 = a * c
s3 = b * c
slack = min(s1,s2,s3)
return 2*(s1+s2+s3)+slack
R = 0
for l in sys.stdin.readlines():
n = processline(l[:-1])
R += n
print(R)

16
d02/part2.py Normal file
View File

@ -0,0 +1,16 @@
import sys
def processline(l):
# a x b x c
(a,b,c) = tuple(map(int,l.split('x')))
print(l, a,b,c)
A = sorted([a,b,c])
s1 = A[0]
s2 = A[1]
return 2*(s1+s2)+a*b*c
R = 0
for l in sys.stdin.readlines():
n = processline(l[:-1])
R += n
print(R)

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))