commit ca06c26658b34448aba4014193179dfdd7b19d33 Author: setop Date: Fri Dec 1 10:42:13 2023 +0100 three first days on first try! diff --git a/d01/part1.py b/d01/part1.py new file mode 100644 index 0000000..83195f8 --- /dev/null +++ b/d01/part1.py @@ -0,0 +1,6 @@ +import sys + +s = sys.stdin.read()[:-1] + +print(sum(map(lambda c: [-1,1][c=='('],s))) + diff --git a/d01/part2.py b/d01/part2.py new file mode 100644 index 0000000..cb54728 --- /dev/null +++ b/d01/part2.py @@ -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 diff --git a/d02/part1.py b/d02/part1.py new file mode 100644 index 0000000..3aa0021 --- /dev/null +++ b/d02/part1.py @@ -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) diff --git a/d02/part2.py b/d02/part2.py new file mode 100644 index 0000000..781cb15 --- /dev/null +++ b/d02/part2.py @@ -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) diff --git a/d03/part1.py b/d03/part1.py new file mode 100644 index 0000000..1aa2cf0 --- /dev/null +++ b/d03/part1.py @@ -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)) + diff --git a/d03/part2.py b/d03/part2.py new file mode 100644 index 0000000..12341e2 --- /dev/null +++ b/d03/part2.py @@ -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)) +