day 6 solution
parent
cfdab32f3f
commit
b480088127
|
@ -0,0 +1,2 @@
|
|||
Time: 48 87 69 81
|
||||
Distance: 255 1288 1117 1623
|
|
@ -0,0 +1,2 @@
|
|||
Time: 7 15 30
|
||||
Distance: 9 40 200
|
|
@ -0,0 +1,38 @@
|
|||
sample = {
|
||||
"time": [7, 15, 30],
|
||||
"distance": [9, 40, 200],
|
||||
}
|
||||
|
||||
input = {
|
||||
"time": [ 48, 87, 69, 81,],
|
||||
"distance": [ 255, 1288, 1117, 1623,],
|
||||
}
|
||||
|
||||
|
||||
def solve(data):
|
||||
time = data["time"]
|
||||
dist = data["distance"]
|
||||
|
||||
part1 = 1
|
||||
for t, best in zip(time, dist):
|
||||
ways = 0
|
||||
for i in range(t):
|
||||
v = i
|
||||
d = (t-i)*v
|
||||
if d > best:
|
||||
ways += 1
|
||||
part1 *= ways
|
||||
|
||||
return part1
|
||||
|
||||
print(solve(sample))
|
||||
print(solve(input))
|
||||
|
||||
def part2(data):
|
||||
return {"time": [int("".join(str(x) for x in data["time"]))],
|
||||
"distance": [int("".join(str(x) for x in data["distance"]))]}
|
||||
|
||||
print(solve(part2(sample)))
|
||||
print(solve(part2(input)))
|
||||
|
||||
|
Loading…
Reference in New Issue