zenithstar95

I love you Aymeric

  • he/him

28 - queer dude - irish - 🏳️‍🌈🏳️‍⚧️🏴
__
Software dev.
I draw suggestive things sometimes.
__
Boyfriend: @hephaistos


CSS Adventurer Plate Generator
stellarzenith.github.io/adventurer-plate/

This was easy. I do want to redo part 2 to be faster though because it currently takes 9 seconds to complete.


Part 1

with open("input.txt", "r") as f:
    input = f.readlines()

times = input[0].split(":")[1].split()
distances = input[1].split(":")[1].split()
races = []
for i in range(len(times)):
    races.append(dict(time=int(times[i]), distance=int(distances[i])))

total = 1
for race in races:
    ways_to_win = 0
    for ms in range(race["time"]):
        if (ms * (race["time"] - ms)) > race["distance"]:
            ways_to_win += 1
    total *= ways_to_win
print(total)
syntax highlighting by codehost

Part 2

with open("input.txt", "r") as f:
    input = f.readlines()

time = int(input[0].split(":")[1].replace(" ", ""))
distance = int(input[1].split(":")[1].replace(" ", ""))
race = dict(time=time, distance=distance)

total = 1
ways_to_win = 0
for ms in range(race["time"]):
    if (ms * (race["time"] - ms)) > race["distance"]:
        ways_to_win += 1
total *= ways_to_win
print(total)
syntax highlighting by codehost

You must log in to comment.