Skip to content

Commit

Permalink
2023 day 6
Browse files Browse the repository at this point in the history
  • Loading branch information
TomW1605 committed Dec 6, 2023
1 parent 9229e0d commit 999cc79
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 0 deletions.
58 changes: 58 additions & 0 deletions 2023 - Python/Day 6/Day6.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import re

from readFile import readFile


def part1(input_lines):
print(input_lines)

times = [int(x) for x in re.split(' +', input_lines[0])[1:]]
dists = [int(x) for x in re.split(' +', input_lines[1])[1:]]
races = [(times[ii], dists[ii]) for ii in range(len(times))]

print(races)

total = 1

for time, dist in races:
win_options = 0
# print(time)
# print(dist)
for held in range(time):
if (time-held)*held > dist:
win_options += 1
total *= win_options

print(total)

def part2(input_lines):
print(input_lines)

time = int(input_lines[0].replace(' ', '').split(':')[1])
dist = int(input_lines[1].replace(' ', '').split(':')[1])

print(time)
print(dist)

win_options = 0
for held in range(time):
if (time - held) * held > dist:
win_options += 1

print(win_options)


if __name__ == '__main__':
test = 1
part = 2

if test:
inputLines = readFile("testInput.txt")
else:
inputLines = readFile("input.txt")

if part == 1:
part1(inputLines)
elif part == 2:
part2(inputLines)

2 changes: 2 additions & 0 deletions 2023 - Python/Day 6/input.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Time: 51 69 98 78
Distance: 377 1171 1224 1505
2 changes: 2 additions & 0 deletions 2023 - Python/Day 6/testInput.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Time: 7 15 30
Distance: 9 40 200

0 comments on commit 999cc79

Please sign in to comment.