-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
62 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
Time: 51 69 98 78 | ||
Distance: 377 1171 1224 1505 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
Time: 7 15 30 | ||
Distance: 9 40 200 |