From a883b4adad390f605d685bce16b1316569ed6568 Mon Sep 17 00:00:00 2001 From: FrederikBaerentsen Date: Wed, 6 Dec 2023 19:08:19 +0100 Subject: [PATCH] Finished 2023-12-06 part 1 + 2 --- 2023/day6/input | 2 ++ 2023/day6/part1.py | 47 +++++++++++++++++++++++++++++++--------------- 2023/day6/part2.py | 33 ++++++++++++++++++++++++++++++++ 3 files changed, 67 insertions(+), 15 deletions(-) create mode 100644 2023/day6/input create mode 100644 2023/day6/part2.py diff --git a/2023/day6/input b/2023/day6/input new file mode 100644 index 0000000..71523ae --- /dev/null +++ b/2023/day6/input @@ -0,0 +1,2 @@ +Time: 60 94 78 82 +Distance: 475 2138 1015 1650 diff --git a/2023/day6/part1.py b/2023/day6/part1.py index c26d9e5..2a8152e 100644 --- a/2023/day6/part1.py +++ b/2023/day6/part1.py @@ -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) diff --git a/2023/day6/part2.py b/2023/day6/part2.py new file mode 100644 index 0000000..3f50d75 --- /dev/null +++ b/2023/day6/part2.py @@ -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)