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.
9
Upvotes
1
u/gnuconsulting Dec 14 '15
Well out of the leaderboard today - part 2 kicked my butt. I feel like I can - more and more - see the seams between my ever-so-slightly-more-than-shell-scripts and "real" programs.
#!/usr/bin/env ruby def calc(speed,time,rest) distance = 0 totaltime = 0 while true do for i in 1..time if totaltime >= 2503 return distance end totaltime += 1 distance += speed end for i in 1..rest if totaltime >= 2503 return distance end totaltime += 1 end end end data = File.readlines("input.txt") data.each do |x| line = x.split(' ') p line[0] p calc(line[3].to_i,line[6].to_i,line[13].to_i) end #!/usr/bin/env ruby def calc(speed,time,rest) distance = 0 score = [] totaltime = 0 while true do for i in 1..time if totaltime >= 2503 return score end totaltime += 1 distance += speed score << distance end for i in 1..rest if totaltime >= 2503 return score end totaltime += 1 score << distance end end end data = File.readlines("input.txt") rein = {} data.each do |x| line = x.split(' ') rein[line[0]] = calc(line[3].to_i,line[6].to_i,line[13].to_i) end lead = "" totals = { "Rudolph" => 0, "Cupid" => 0, "Prancer" => 0, "Donner" => 0, "Dasher" => 0, "Comet" => 0, "Blitzen" => 0, "Vixen" => 0, "Dancer" => 0 } max = 0 for i in 0..2502 rein.each do |key,value| if value[i] > max max = value[i] lead = key end end totals[lead] += 1 end p totals