Finished 2023-12-06 part 1 + 2

This commit is contained in:
FrederikBaerentsen 2023-12-06 19:08:19 +01:00
parent 32aa4dc108
commit a883b4adad
3 changed files with 67 additions and 15 deletions

2
2023/day6/input Normal file
View File

@ -0,0 +1,2 @@
Time: 60 94 78 82
Distance: 475 2138 1015 1650

View File

@ -2,7 +2,7 @@
import sys
from pprint import pprint
import numpy as np
input_f = sys.argv[1]
@ -11,19 +11,36 @@ arr = []
from aocd import get_data
maps = map(get_data(2023,6))
print(maps)
with open(input_f) as file:
for line in file:
tmp = line.rstrip()
tmp = tmp.split()
arr.append(tmp)
# continue
# t = tmp[idx]
# r = tmp[len(tmp)]
# #print(t,r)
#print(get_data(day=6,year=2023))
maps = open(input_f).read().splitlines()
maps = [l.split() for l in maps]
pprint(maps)
total_winnings = []
for i in range(0,len(maps[0])):
if i == 0:
continue
time = int(maps[0][i])
max_dist = int(maps[1][i])
hold = 0
dist = 0
total_winnings.append(0)
print(total_winnings)
print('Start\t',end='')
print(maps[0][i],maps[1][i])
print('Time\tDist\tHold')
for j in range(1,int(maps[0][i])+1):
while time > 0:
time -= 1
hold += 1
dist = hold * time
won = False
print(str(time)+ '\t' + str(dist) + '\t' + str(hold) + '\t',end='')
if dist > max_dist:
total_winnings[i-1] += 1
print('won')
else:
print()
print(np.prod(total_winnings))
print(total_winnings)

33
2023/day6/part2.py Normal file
View File

@ -0,0 +1,33 @@
#!/bin/python3
import sys
from pprint import pprint
import numpy as np
#time = 71530
#max_dist = 940200
# too lazy to write a parser
time = 60947882
max_dist = 475213810151650
total_winnings = 0
hold = 0
dist = 0
print('Time\tDist\tHold')
for j in range(1,time+1):
while time > 0:
print(time)
time -= 1
hold += 1
dist = hold * time
won = False
#print(str(time)+ '\t' + str(dist) + '\t' + str(hold) + '\t',end='')
if dist > max_dist:
total_winnings += 1
#print('won')
#else:
# print()
print(total_winnings)