Combine AoC Repos
This commit is contained in:
9
2015/day14/input
Normal file
9
2015/day14/input
Normal file
@@ -0,0 +1,9 @@
|
||||
Vixen can fly 19 km/s for 7 seconds, but then must rest for 124 seconds.
|
||||
Rudolph can fly 3 km/s for 15 seconds, but then must rest for 28 seconds.
|
||||
Donner can fly 19 km/s for 9 seconds, but then must rest for 164 seconds.
|
||||
Blitzen can fly 19 km/s for 9 seconds, but then must rest for 158 seconds.
|
||||
Comet can fly 13 km/s for 7 seconds, but then must rest for 82 seconds.
|
||||
Cupid can fly 25 km/s for 6 seconds, but then must rest for 145 seconds.
|
||||
Dasher can fly 14 km/s for 3 seconds, but then must rest for 38 seconds.
|
||||
Dancer can fly 3 km/s for 16 seconds, but then must rest for 37 seconds.
|
||||
Prancer can fly 25 km/s for 6 seconds, but then must rest for 143 seconds.
|
88
2015/day14/main.go
Normal file
88
2015/day14/main.go
Normal file
@@ -0,0 +1,88 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"fmt"
|
||||
"os"
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func main() {
|
||||
if len(os.Args) < 2 {
|
||||
fmt.Println("Usage: day14 <seconds>")
|
||||
os.Exit(1)
|
||||
}
|
||||
raceTime := os.Args[1]
|
||||
var input []string
|
||||
scanner := bufio.NewScanner(os.Stdin)
|
||||
for scanner.Scan() {
|
||||
input = append(input, scanner.Text())
|
||||
}
|
||||
|
||||
var allDeer []deer
|
||||
for i := range input {
|
||||
parts := strings.Split(input[i], " ")
|
||||
allDeer = append(allDeer, *createDeer(
|
||||
parts[0],
|
||||
mustAtoi(parts[3]),
|
||||
mustAtoi(parts[6]),
|
||||
mustAtoi(parts[13]),
|
||||
))
|
||||
}
|
||||
fmt.Println("Race ends at " + raceTime)
|
||||
endTime := mustAtoi(raceTime)
|
||||
deerStars := make(map[string]int)
|
||||
for i := 1; i <= endTime; i++ {
|
||||
var topVal int
|
||||
for j := range allDeer {
|
||||
tmp := allDeer[j].travelFor(i)
|
||||
if tmp > topVal {
|
||||
topVal = tmp
|
||||
}
|
||||
}
|
||||
for j := range allDeer {
|
||||
if allDeer[j].travelFor(i) == topVal {
|
||||
deerStars[allDeer[j].name]++
|
||||
}
|
||||
}
|
||||
}
|
||||
for i := range deerStars {
|
||||
fmt.Println(i + ": " + strconv.Itoa(deerStars[i]))
|
||||
}
|
||||
}
|
||||
|
||||
type deer struct {
|
||||
name string
|
||||
speed int
|
||||
moveDuration int
|
||||
restDuration int
|
||||
}
|
||||
|
||||
func createDeer(n string, s, m, r int) *deer {
|
||||
d := deer{n, s, m, r}
|
||||
return &d
|
||||
}
|
||||
|
||||
func (d *deer) travelFor(s int) int {
|
||||
var dist int
|
||||
for s > 0 {
|
||||
if s > d.moveDuration {
|
||||
dist += d.speed * d.moveDuration
|
||||
} else {
|
||||
dist += d.speed * s
|
||||
}
|
||||
s -= d.moveDuration
|
||||
s -= d.restDuration
|
||||
}
|
||||
return dist
|
||||
}
|
||||
|
||||
func mustAtoi(s string) int {
|
||||
var i int
|
||||
var err error
|
||||
if i, err = strconv.Atoi(s); err != nil {
|
||||
fmt.Println("Tried to atoi " + s)
|
||||
}
|
||||
return i
|
||||
}
|
84
2015/day14/problem
Normal file
84
2015/day14/problem
Normal file
@@ -0,0 +1,84 @@
|
||||
Advent of Code
|
||||
|
||||
br0xen 40*
|
||||
|
||||
• [About]
|
||||
• [Stats]
|
||||
• [Leaderboard]
|
||||
• [Settings]
|
||||
• [Log out]
|
||||
|
||||
--- Day 14: Reindeer Olympics ---
|
||||
|
||||
This year is the Reindeer Olympics! Reindeer can fly at high speeds, but must rest occasionally
|
||||
to recover their energy. Santa would like to know which of his reindeer is fastest, and so he
|
||||
has them race.
|
||||
|
||||
Reindeer can only either be flying (always at their top speed) or resting (not moving at all),
|
||||
and always spend whole seconds in either state.
|
||||
|
||||
For example, suppose you have the following Reindeer:
|
||||
|
||||
• Comet can fly 14 km/s for 10 seconds, but then must rest for 127 seconds.
|
||||
• Dancer can fly 16 km/s for 11 seconds, but then must rest for 162 seconds.
|
||||
|
||||
After one second, Comet has gone 14 km, while Dancer has gone 16 km. After ten seconds, Comet
|
||||
has gone 140 km, while Dancer has gone 160 km. On the eleventh second, Comet begins resting
|
||||
(staying at 140 km), and Dancer continues on for a total distance of 176 km. On the 12th
|
||||
second, both reindeer are resting. They continue to rest until the 138th second, when Comet
|
||||
flies for another ten seconds. On the 174th second, Dancer flies for another 11 seconds.
|
||||
|
||||
In this example, after the 1000th second, both reindeer are resting, and Comet is in the lead
|
||||
at 1120 km (poor Dancer has only gotten 1056 km by that point). So, in this situation, Comet
|
||||
would win (if the race ended at 1000 seconds).
|
||||
|
||||
Given the descriptions of each reindeer (in your puzzle input), after exactly 2503 seconds,
|
||||
what distance has the winning reindeer traveled?
|
||||
|
||||
Your puzzle answer was 2660.
|
||||
|
||||
--- Part Two ---
|
||||
|
||||
Seeing how reindeer move in bursts, Santa decides he's not pleased with the old scoring system.
|
||||
|
||||
Instead, at the end of each second, he awards one point to the reindeer currently in the lead.
|
||||
(If there are multiple reindeer tied for the lead, they each get one point.) He keeps the
|
||||
traditional 2503 second time limit, of course, as doing otherwise would be entirely ridiculous.
|
||||
|
||||
Given the example reindeer from above, after the first second, Dancer is in the lead and gets
|
||||
one point. He stays in the lead until several seconds into Comet's second burst: after the
|
||||
140th second, Comet pulls into the lead and gets his first point. Of course, since Dancer had
|
||||
been in the lead for the 139 seconds before that, he has accumulated 139 points by the 140th
|
||||
second.
|
||||
|
||||
After the 1000th second, Dancer has accumulated 689 points, while poor Comet, our old champion,
|
||||
only has 312. So, with the new scoring system, Dancer would win (if the race ended at 1000
|
||||
seconds).
|
||||
|
||||
Again given the descriptions of each reindeer (in your puzzle input), after exactly 2503
|
||||
seconds, how many points does the winning reindeer have?
|
||||
|
||||
Your puzzle answer was 1256.
|
||||
|
||||
Both parts of this puzzle are complete! They provide two gold stars: **
|
||||
|
||||
At this point, you should return to your advent calendar and try another puzzle.
|
||||
|
||||
If you still want to see it, you can get your puzzle input.
|
||||
|
||||
You can also [Shareon Twitter Google+ Reddit] this puzzle.
|
||||
|
||||
References
|
||||
|
||||
Visible links
|
||||
. http://adventofcode.com/
|
||||
. http://adventofcode.com/about
|
||||
. http://adventofcode.com/stats
|
||||
. http://adventofcode.com/leaderboard
|
||||
. http://adventofcode.com/settings
|
||||
. http://adventofcode.com/auth/logout
|
||||
. http://adventofcode.com/
|
||||
. http://adventofcode.com/day/14/input
|
||||
. https://twitter.com/intent/tweet?text=I%27ve+completed+%22Reindeer+Olympics%22+%2D+Day+14+%2D+Advent+of+Code&url=http%3A%2F%2Fadventofcode%2Ecom%2Fday%2F14&related=ericwastl&hashtags=AdventOfCode
|
||||
. https://plus.google.com/share?url=http%3A%2F%2Fadventofcode%2Ecom%2Fday%2F14
|
||||
. http://www.reddit.com/submit?url=http%3A%2F%2Fadventofcode%2Ecom%2Fday%2F14&title=I%27ve+completed+%22Reindeer+Olympics%22+%2D+Day+14+%2D+Advent+of+Code
|
2
2015/day14/sample_input
Normal file
2
2015/day14/sample_input
Normal file
@@ -0,0 +1,2 @@
|
||||
Comet can fly 14 km/s for 10 seconds, but then must rest for 127 seconds.
|
||||
Dancer can fly 16 km/s for 11 seconds, but then must rest for 162 seconds.
|
Reference in New Issue
Block a user