Combine AoC Repos
This commit is contained in:
1
2015/day20/input
Normal file
1
2015/day20/input
Normal file
@@ -0,0 +1 @@
|
||||
36000000
|
112
2015/day20/main.go
Normal file
112
2015/day20/main.go
Normal file
@@ -0,0 +1,112 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
func main() {
|
||||
if len(os.Args) < 2 {
|
||||
fmt.Println("Usage: day20 <number>")
|
||||
os.Exit(1)
|
||||
}
|
||||
numPresents := mustAtoi(os.Args[1])
|
||||
|
||||
// 831600 was the lowest for part 1
|
||||
// Part 2 won't be lower, so...
|
||||
// 884520 for Part 2?
|
||||
houseNum := 884500
|
||||
k := receivedPresentsPt2(houseNum)
|
||||
lastFound := houseNum
|
||||
for {
|
||||
houseNum = houseNum + 10
|
||||
k = receivedPresentsPt2(houseNum)
|
||||
if k >= (numPresents / 4 * 3) {
|
||||
fmt.Print("O")
|
||||
} else if k >= numPresents/2 {
|
||||
fmt.Print("o")
|
||||
} else if k >= numPresents/4 {
|
||||
fmt.Print(".")
|
||||
}
|
||||
if k >= numPresents {
|
||||
fmt.Print(" House number " + strconv.Itoa(houseNum) + " received " + strconv.Itoa(k) + " presents.")
|
||||
fmt.Println("(" + strconv.Itoa(lastFound-houseNum) + ")")
|
||||
lastFound = houseNum
|
||||
}
|
||||
}
|
||||
/*
|
||||
for houseNum > 40000 { //k < numPresents {
|
||||
if houseNum%100000 == 0 {
|
||||
fmt.Print("o")
|
||||
} else if houseNum%1000 == 0 {
|
||||
fmt.Print(".")
|
||||
}
|
||||
houseNum = houseNum - 10 //-- // = houseNum - 360
|
||||
k = receivedPresentsPt1(houseNum)
|
||||
if k >= numPresents {
|
||||
fmt.Print(" House number " + strconv.Itoa(houseNum) + " received " + strconv.Itoa(k) + " presents.")
|
||||
fmt.Println("(" + strconv.Itoa(lastFound-houseNum) + ")")
|
||||
lastFound = houseNum
|
||||
}
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
func receivedPresentsPt2(house int) int {
|
||||
var ret int
|
||||
elves := getFactors(house)
|
||||
for i := range elves {
|
||||
if (house / elves[i]) <= 50 {
|
||||
ret += elves[i] * 11
|
||||
}
|
||||
}
|
||||
return ret
|
||||
}
|
||||
|
||||
func receivedPresentsPt1(house int) int {
|
||||
var ret int
|
||||
elves := getFactors(house)
|
||||
for i := range elves {
|
||||
ret += elves[i] * 10
|
||||
}
|
||||
return ret
|
||||
}
|
||||
|
||||
func getFactors(n int) []int {
|
||||
var ret []int
|
||||
bot := 1
|
||||
top := n
|
||||
for bot < n/2 {
|
||||
if n%bot == 0 {
|
||||
top = n / bot
|
||||
if top == bot {
|
||||
ret = addUnique(ret, bot)
|
||||
} else {
|
||||
ret = addUnique(ret, bot)
|
||||
ret = addUnique(ret, top)
|
||||
}
|
||||
}
|
||||
bot++
|
||||
}
|
||||
return ret
|
||||
}
|
||||
|
||||
func addUnique(sl []int, n int) []int {
|
||||
for i := 0; i < len(sl); i++ {
|
||||
if sl[i] == n {
|
||||
return sl
|
||||
}
|
||||
}
|
||||
return append(sl, n)
|
||||
}
|
||||
|
||||
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)
|
||||
os.Exit(1)
|
||||
}
|
||||
return i
|
||||
}
|
77
2015/day20/problem
Normal file
77
2015/day20/problem
Normal file
@@ -0,0 +1,77 @@
|
||||
Advent of Code
|
||||
|
||||
br0xen 40*
|
||||
|
||||
• [About]
|
||||
• [Stats]
|
||||
• [Leaderboard]
|
||||
• [Settings]
|
||||
• [Log out]
|
||||
|
||||
--- Day 20: Infinite Elves and Infinite Houses ---
|
||||
|
||||
To keep the Elves busy, Santa has them deliver some presents by hand, door-to-door. He sends
|
||||
them down a street with infinite houses numbered sequentially: 1, 2, 3, 4, 5, and so on.
|
||||
|
||||
Each Elf is assigned a number, too, and delivers presents to houses based on that number:
|
||||
|
||||
• The first Elf (number 1) delivers presents to every house: 1, 2, 3, 4, 5, ....
|
||||
• The second Elf (number 2) delivers presents to every second house: 2, 4, 6, 8, 10, ....
|
||||
• Elf number 3 delivers presents to every third house: 3, 6, 9, 12, 15, ....
|
||||
|
||||
There are infinitely many Elves, numbered starting with 1. Each Elf delivers presents equal to
|
||||
ten times his or her number at each house.
|
||||
|
||||
So, the first nine houses on the street end up like this:
|
||||
|
||||
House 1 got 10 presents.
|
||||
House 2 got 30 presents.
|
||||
House 3 got 40 presents.
|
||||
House 4 got 70 presents.
|
||||
House 5 got 60 presents.
|
||||
House 6 got 120 presents.
|
||||
House 7 got 80 presents.
|
||||
House 8 got 150 presents.
|
||||
House 9 got 130 presents.
|
||||
|
||||
The first house gets 10 presents: it is visited only by Elf 1, which delivers 1 * 10 = 10
|
||||
presents. The fourth house gets 70 presents, because it is visited by Elves 1, 2, and 4, for a
|
||||
total of 10 + 20 + 40 = 70 presents.
|
||||
|
||||
What is the lowest house number of the house to get at least as many presents as the number in
|
||||
your puzzle input?
|
||||
|
||||
Your puzzle answer was 831600.
|
||||
|
||||
--- Part Two ---
|
||||
|
||||
The Elves decide they don't want to visit an infinite number of houses. Instead, each Elf will
|
||||
stop after delivering presents to 50 houses. To make up for it, they decide to deliver presents
|
||||
equal to eleven times their number at each house.
|
||||
|
||||
With these changes, what is the new lowest house number of the house to get at least as many
|
||||
presents as the number in your puzzle input?
|
||||
|
||||
Your puzzle answer was 884520.
|
||||
|
||||
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.
|
||||
|
||||
Your puzzle input was 36000000.
|
||||
|
||||
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/
|
||||
. https://twitter.com/intent/tweet?text=I%27ve+completed+%22Infinite+Elves+and+Infinite+Houses%22+%2D+Day+20+%2D+Advent+of+Code&url=http%3A%2F%2Fadventofcode%2Ecom%2Fday%2F20&related=ericwastl&hashtags=AdventOfCode
|
||||
. https://plus.google.com/share?url=http%3A%2F%2Fadventofcode%2Ecom%2Fday%2F20
|
||||
. http://www.reddit.com/submit?url=http%3A%2F%2Fadventofcode%2Ecom%2Fday%2F20&title=I%27ve+completed+%22Infinite+Elves+and+Infinite+Houses%22+%2D+Day+20+%2D+Advent+of+Code
|
Reference in New Issue
Block a user