Compare commits

...

2 Commits

Author SHA1 Message Date
kwout a7aa40381e 2024 day 1 solved 2 months ago
kwout c02f2ec040 2023 dday 10 solved 3 months ago
  1. 53
      2023/10.py
  2. 16
      2024/1.py
  3. 3
      README.md

@ -0,0 +1,53 @@
input = [[i for i in l] for l in open("input.txt", 'r').read().splitlines()]
traversed = []
whereami = (0, 0)
next = (0,0)
for x in range(len(input)):
for y in range(len(input[x])):
if input[x][y] == 'S':
whereami = (x, y)
if x > 0 and input[x-1][y] in ['|', '7', 'F']:
next = (x-1, y)
break
if x+1 < len(input) and input[x+1][y] in ['|', 'L', 'J']:
next = (x+1, y)
break
if y > 0 and input[x][y-1] in ['-', 'L', 'F']:
next = (x, y-1)
break
if y+1 < len(input[0]) and input[x][y+1] in ['-', '7', 'J']:
next = (x, y+1)
break
while True:
x, y = next
traversed.append((x,y))
if input[x][y] == 'F':
next = (x+1, y) if whereami == (x,y+1) else (x, y+1)
elif input[x][y] == '|':
next = (x+1, y) if whereami == (x-1,y) else (x-1, y)
elif input[x][y] == '-':
next = (x, y+1) if whereami == (x,y-1) else (x, y-1)
elif input[x][y] == 'L':
next = (x-1, y) if whereami == (x,y+1) else (x, y+1)
elif input[x][y] == 'J':
next = (x-1, y) if whereami == (x,y-1) else (x, y-1)
elif input[x][y] == '7':
next = (x+1, y) if whereami == (x,y-1) else (x, y-1)
if next in traversed:
break
whereami = (x, y)
print(len(traversed)/2)
area = 0
for i in range(len(traversed)-1):
area += (traversed[i][1] + traversed[i+1][1]) * (traversed[i][0] - traversed[i+1][0])
area += (traversed[-1][1] + traversed[0][1]) * (traversed[-1][0] - traversed[0][0])
area = abs(area / 2)
points = area - len(traversed) / 2 + 1
print(points)

@ -0,0 +1,16 @@
list1, list2, summa, summa2 = [], [], 0, 0
for l in open("input.txt", 'r').read().splitlines():
tup = [int(n) for n in l.split(' ')]
list1.append(tup[0])
list2.append(tup[1])
list1.sort()
list2.sort()
for i in range(len(list1)):
summa += abs(list1[i] - list2[i])
summa2 += list2.count(list1[i]) * list1[i]
print(summa)
print(summa2)

@ -3,7 +3,8 @@ my solutions for the [Advent of Code](https://adventofcode.com/)
in progress:\ in progress:\
2021: 12/25\ 2021: 12/25\
2022: 8/25\ 2022: 8/25\
2023: 9/25 2023: 9/25\
2024: 0/25
planned:\ planned:\
2020\ 2020\

Loading…
Cancel
Save