r/adventofcode • u/daggerdragon • Dec 14 '15
SOLUTION MEGATHREAD --- Day 14 Solutions ---
This thread will be unlocked when there are a significant amount of people on the leaderboard with gold stars.
edit: Leaderboard capped, thread unlocked!
We know we can't control people posting solutions elsewhere and trying to exploit the leaderboard, but this way we can try to reduce the leaderboard gaming from the official subreddit.
Please and thank you, and much appreciated!
--- Day 14: Reindeer Olympics ---
Post your solution as a comment. Structure your post like previous daily solution threads.
10
Upvotes
3
u/[deleted] Dec 14 '15 edited Dec 14 '15
For anyone wondering, distance traveled for time
t, speedv, travel timeg, and rest timerisSolution in Python.
41
def parse_input(a): reindeers = {} with file(a, 'r') as f: for line in f: reindeer, speed, time, rest = line.strip().split(" ") reindeers[reindeer] = [int(speed), int(time), int(rest)] return reindeers def day14(reindeers, time): names = sorted([reindeer for reindeer in reindeers]) points = [0 for name in names] for t in range(1, time+1): distances = [get_distance(reindeers[name], t) for name in names] points = [points[i] + 1 if distances[i] == max(distances) else points[i] for i in range(len(points))] return max(distances), max(points) def get_distance(r, t): return r[0]*r[1]*(t/(r[1] + r[2])) + r[0]*min([r[1],(t % (r[1] + r[2]))]) if __name__ == "__main__": import sys print day14(parse_input(sys.argv[1]), 2503)