diff --git a/2023/Day-06/day06-1.py b/2023/Day-06/day06-1.py new file mode 100755 index 0000000..ba18a59 --- /dev/null +++ b/2023/Day-06/day06-1.py @@ -0,0 +1,32 @@ +#!/usr/bin/python3 + +from math import prod + +def main(): + times = [] + distances = [] + records = {} + + with open('input.txt', 'r') as input_file: + for line in input_file: + if line.startswith('Time:'): + times = line.split(':')[1].split() + elif line.startswith('Distance:'): + distances = line.split(':')[1].split() + + for time in times: + records[int(time)] = int(distances[times.index(time)]) + + num_winners = [] + for total_time in records: + winners = [] + for time_pressed in range(total_time + 1): + distance_traveled = time_pressed * (total_time - time_pressed) + if distance_traveled > records[total_time]: + winners.append(time_pressed) + num_winners.append(len(winners)) + + print(prod(num_winners)) + +if __name__ == '__main__': + main() diff --git a/2023/Day-06/day06-2.py b/2023/Day-06/day06-2.py new file mode 100755 index 0000000..1ddd089 --- /dev/null +++ b/2023/Day-06/day06-2.py @@ -0,0 +1,32 @@ +#!/usr/bin/python3 + +from math import prod + +def main(): + times = [] + distances = [] + records = {} + + with open('input.txt', 'r') as input_file: + for line in input_file: + if line.startswith('Time:'): + times = [line.strip().split(':')[1].replace(' ', '')] + elif line.startswith('Distance:'): + distances = [line.strip().split(':')[1].replace(' ', '')] + + for time in times: + records[int(time)] = int(distances[times.index(time)]) + + num_winners = [] + for total_time in records: + winners = [] + for time_pressed in range(total_time + 1): + distance_traveled = time_pressed * (total_time - time_pressed) + if distance_traveled > records[total_time]: + winners.append(time_pressed) + num_winners.append(len(winners)) + + print(prod(num_winners)) + +if __name__ == '__main__': + main()