day6: solve both parts
This commit is contained in:
parent
1c5ffa221b
commit
cd72bdfd14
|
@ -0,0 +1,28 @@
|
|||
with open("data/input.txt", "r") as f:
|
||||
data = f.read()
|
||||
|
||||
data = data.split("\n")
|
||||
times = data[0].split(":")[1].split()
|
||||
distances = data[1].split(":")[1].split()
|
||||
|
||||
times = [int(i) for i in times]
|
||||
distances = [int(i) for i in distances]
|
||||
|
||||
# print(times)
|
||||
# print(distances)
|
||||
|
||||
product = 1
|
||||
|
||||
|
||||
def distance(pressed_duration, limit_duration):
|
||||
return pressed_duration * (limit_duration - pressed_duration)
|
||||
|
||||
|
||||
for time, dist in zip(times, distances):
|
||||
count = 0
|
||||
for i in range(0, time + 1):
|
||||
if distance(i, time) > dist:
|
||||
count += 1
|
||||
product *= count
|
||||
|
||||
print(product)
|
|
@ -0,0 +1,28 @@
|
|||
with open("data/sample.txt", "r") as f:
|
||||
data = f.read()
|
||||
|
||||
data = data.split("\n")
|
||||
times = data[0].split(":")[1].replace(" ", "").split()
|
||||
distances = data[1].split(":")[1].replace(" ", "").split()
|
||||
|
||||
times = [int(i) for i in times]
|
||||
distances = [int(i) for i in distances]
|
||||
|
||||
# print(times)
|
||||
# print(distances)
|
||||
|
||||
product = 1
|
||||
|
||||
|
||||
def distance(pressed_duration, limit_duration):
|
||||
return pressed_duration * (limit_duration - pressed_duration)
|
||||
|
||||
|
||||
for time, dist in zip(times, distances):
|
||||
count = 0
|
||||
for i in range(0, time + 1):
|
||||
if distance(i, time) > dist:
|
||||
count += 1
|
||||
product *= count
|
||||
|
||||
print(product)
|
Loading…
Reference in New Issue