Advent of Code 2023 (25 Part Series)
1 Advent of Code 2023
2 Advent of Code 2023 – December 2nd
… 21 more parts…
3 Advent of Code 2023 – December 3rd
4 Advent of Code 2023 – December 4th
5 Advent of Code 2023 – December 5th
6 Advent of Code 2023 – December 6th
7 Advent of Code 2023 – December 7th
8 Advent of Code 2023 – December 8th
9 Advent of Code 2023 – December 9th
10 Advent of Code 2023 – December 10th
11 Advent of Code 2023 – December 11th
12 Advent of Code 2023 – December 12th
13 Advent of Code 2023 – December 13th
14 Advent of Code 2023 – December 14th
15 Advent of Code 2023 – December 15th
16 Advent of Code 2023 – December 16th
17 Advent of Code 2023 – December 17th
18 Advent of Code 2023 – December 18th
19 Advent of Code 2023 – December 19th
20 Advent of Code 2023 – December 20th
21 Advent of Code 2023 – December 21st
22 Advent of Code 2023 – December 22nd
23 Advent of Code 2023 – December 23rd
24 Advent of Code 2023 – December 24th
25 Advent of Code 2023 – December 25th
In this series, I’ll share my progress with the 2023 version of Advent of Code.
Check the first post for a short intro to this series.
You can also follow my progress on GitHub.
December 6th
The puzzle of day 6 took me only half an hour. I’m using a brute-force implementation for the second part, which is a bit disappointing but I need the saved time for the second part of yesterday’s puzzle.
My pitfall for this puzzle: The second part of the puzzle deserves something better than the current brute-force implementation. Unfortunately, I could spend no more time on it.
Solution here, do not click if you want to solve the puzzle first yourself
#!/usr/bin/env python3 import math
import re
with open('input-small.txt') as infile:
lines = infile.readlines()
times = [t for t in re.split('\s+', lines[0].split(':')[1].strip())]
distances = [d for d in re.split('\s+', lines[1].split(':')[1].strip())]
ways = []
for index, t in enumerate([int (t) for t in times]):
way = 0
for i in range(1, t + 1):
if i * (t - i) > int(distances[index]):
way += 1
ways.append(way)
print(math.prod(ways))
time = int(''.join(times))
distance = int(''.join(distances))
ways = 0
for i in range(1, time + 1):
if i * (time - i) > distance:
ways += 1
print(ways)
Enter fullscreen mode Exit fullscreen mode
That’s it! See you again tomorrow!
Advent of Code 2023 (25 Part Series)
1 Advent of Code 2023
2 Advent of Code 2023 – December 2nd
… 21 more parts…
3 Advent of Code 2023 – December 3rd
4 Advent of Code 2023 – December 4th
5 Advent of Code 2023 – December 5th
6 Advent of Code 2023 – December 6th
7 Advent of Code 2023 – December 7th
8 Advent of Code 2023 – December 8th
9 Advent of Code 2023 – December 9th
10 Advent of Code 2023 – December 10th
11 Advent of Code 2023 – December 11th
12 Advent of Code 2023 – December 12th
13 Advent of Code 2023 – December 13th
14 Advent of Code 2023 – December 14th
15 Advent of Code 2023 – December 15th
16 Advent of Code 2023 – December 16th
17 Advent of Code 2023 – December 17th
18 Advent of Code 2023 – December 18th
19 Advent of Code 2023 – December 19th
20 Advent of Code 2023 – December 20th
21 Advent of Code 2023 – December 21st
22 Advent of Code 2023 – December 22nd
23 Advent of Code 2023 – December 23rd
24 Advent of Code 2023 – December 24th
25 Advent of Code 2023 – December 25th
暂无评论内容