Skip to content

Commit bfa011f

Browse files
committed
AoC 2024!!! And what if I get past day 2 this year
1 parent d8ff195 commit bfa011f

File tree

3 files changed

+43
-0
lines changed

3 files changed

+43
-0
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
*/input
2+
*/test-input

01/01a.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
with open('input', 'r') as f:
2+
lines = f.readlines()
3+
4+
left, right = [], []
5+
6+
for line in lines:
7+
l, r = line.split()
8+
left.append(int(l))
9+
right.append(int(r))
10+
11+
left.sort()
12+
right.sort()
13+
14+
if len(left) != len(right): print('fail')
15+
else:
16+
diff = 0
17+
for i in range(len(left)): diff += abs(left[i] - right[i])
18+
print(diff)

01/01b.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
with open('input', 'r') as f:
2+
lines = f.readlines()
3+
4+
left, right = [], []
5+
6+
for line in lines:
7+
l, r = line.split()
8+
left.append(int(l))
9+
right.append(int(r))
10+
11+
right2 = {}
12+
for r_item in right:
13+
if r_item in right2.keys(): right2[r_item] += 1
14+
else: right2[r_item] = 1
15+
16+
print(right2)
17+
18+
similarity = 0
19+
for l_item in left:
20+
if l_item in right2.keys():
21+
similarity += (l_item * right2[l_item])
22+
23+
print(similarity)

0 commit comments

Comments
 (0)