Skip to content

Commit 0f153ef

Browse files
committed
Add day 6 year 2023
1 parent 05bb26d commit 0f153ef

File tree

4 files changed

+41
-0
lines changed

4 files changed

+41
-0
lines changed

2023/day6/input.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Time: 53 71 78 80
2+
Distance: 275 1181 1215 1524

2023/day6/part1.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import re
2+
import math
3+
4+
def solution(input):
5+
a = list(map(lambda x:x.split(":")[1], re.split("\n", input)))
6+
times, distances = list(map(lambda x:re.split(" +",x.strip()), a))
7+
k = 1
8+
for i in range(len(times)):
9+
rs = 0
10+
t = int(times[i])
11+
d = int(distances[i])
12+
x1 = (t - math.sqrt(t**2-4*d))/2
13+
x2 = (t + math.sqrt(t**2-4*d))/2
14+
k *= math.ceil(x2) - math.floor(x1)-1
15+
return k
16+
17+

2023/day6/part2.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import re
2+
import math
3+
4+
def solution(input):
5+
a = list(map(lambda x:re.split(" +",x), input.split("\n")))
6+
i = 1
7+
times = ""
8+
while i < len(a[0]):
9+
times += a[0][i]
10+
i += 1
11+
distances = ""
12+
i = 1
13+
while i < len(a[0]):
14+
distances += a[1][i]
15+
i += 1
16+
t = int(times)
17+
d = int(distances)
18+
x1 = (t - math.sqrt(t**2-4*d))/2
19+
x2 = (t + math.sqrt(t**2-4*d))/2
20+
return math.ceil(x2) - math.floor(x1) -1

2023/day6/sample.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Time: 7 15 30
2+
Distance: 9 40 200

0 commit comments

Comments
 (0)