Combine AoC Repos
This commit is contained in:
parent
5977b28d73
commit
105dbd1ff7
27
.gitignore
vendored
27
.gitignore
vendored
@ -24,4 +24,29 @@ _testmain.go
|
|||||||
*.test
|
*.test
|
||||||
*.prof
|
*.prof
|
||||||
|
|
||||||
othertests
|
# Remove binaries
|
||||||
|
day01/day01
|
||||||
|
day02/day02
|
||||||
|
day03/day03
|
||||||
|
day04/day04
|
||||||
|
day05/day05
|
||||||
|
day06/day06
|
||||||
|
day07/day07
|
||||||
|
day08/day08
|
||||||
|
day09/day09
|
||||||
|
day10/day10
|
||||||
|
day11/day11
|
||||||
|
day12/day12
|
||||||
|
day13/day13
|
||||||
|
day14/day14
|
||||||
|
day15/day15
|
||||||
|
day16/day16
|
||||||
|
day17/day17
|
||||||
|
day18/day18
|
||||||
|
day19/day19
|
||||||
|
day20/day20
|
||||||
|
day21/day21
|
||||||
|
day22/day22
|
||||||
|
day23/day23
|
||||||
|
day24/day24
|
||||||
|
day25/day25
|
||||||
|
1
2015/day01/input
Normal file
1
2015/day01/input
Normal file
File diff suppressed because one or more lines are too long
70
2015/day01/main.go
Normal file
70
2015/day01/main.go
Normal file
@ -0,0 +1,70 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"io"
|
||||||
|
"log"
|
||||||
|
"os"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
var input []string
|
||||||
|
var readInp string
|
||||||
|
for {
|
||||||
|
_, err := fmt.Scan(&readInp)
|
||||||
|
if err != nil {
|
||||||
|
if err != io.EOF {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
break
|
||||||
|
}
|
||||||
|
input = append(input, readInp)
|
||||||
|
}
|
||||||
|
|
||||||
|
var total int
|
||||||
|
var wentToBasement bool
|
||||||
|
var procIdx int
|
||||||
|
for _, k := range input {
|
||||||
|
for i := range k {
|
||||||
|
procIdx++
|
||||||
|
if k[i] == '(' {
|
||||||
|
total++
|
||||||
|
} else if k[i] == ')' {
|
||||||
|
total--
|
||||||
|
}
|
||||||
|
if total < 0 && !wentToBasement {
|
||||||
|
wentToBasement = true
|
||||||
|
fmt.Printf("Went to basement at direction #%d\n", procIdx)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
fmt.Printf("Santa should go to floor %d\n", total)
|
||||||
|
|
||||||
|
fmt.Println("\nBen's Solution:")
|
||||||
|
bens()
|
||||||
|
}
|
||||||
|
|
||||||
|
func bens() {
|
||||||
|
file, err := os.Open("./input")
|
||||||
|
floor := 0
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println(err)
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
|
||||||
|
defer file.Close()
|
||||||
|
for {
|
||||||
|
data := make([]byte, 1)
|
||||||
|
_, err := file.Read(data)
|
||||||
|
if err != nil {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
if data[0] == '(' {
|
||||||
|
floor = floor + 1
|
||||||
|
} else {
|
||||||
|
floor = floor - 1
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
fmt.Printf("Floor: %d\n", floor)
|
||||||
|
}
|
81
2015/day01/problem
Normal file
81
2015/day01/problem
Normal file
@ -0,0 +1,81 @@
|
|||||||
|
Advent of Code
|
||||||
|
|
||||||
|
br0xen 40*
|
||||||
|
|
||||||
|
• [About]
|
||||||
|
• [Stats]
|
||||||
|
• [Leaderboard]
|
||||||
|
• [Settings]
|
||||||
|
• [Log out]
|
||||||
|
|
||||||
|
--- Day 1: Not Quite Lisp ---
|
||||||
|
|
||||||
|
Santa was hoping for a white Christmas, but his weather machine's "snow" function is powered by
|
||||||
|
stars, and he's fresh out! To save Christmas, he needs you to collect fifty stars by December
|
||||||
|
25th.
|
||||||
|
|
||||||
|
Collect stars by helping Santa solve puzzles. Two puzzles will be made available on each day in
|
||||||
|
the advent calendar; the second puzzle is unlocked when you complete the first. Each puzzle
|
||||||
|
grants one star. Good luck!
|
||||||
|
|
||||||
|
Here's an easy puzzle to warm you up.
|
||||||
|
|
||||||
|
Santa is trying to deliver presents in a large apartment building, but he can't find the right
|
||||||
|
floor - the directions he got are a little confusing. He starts on the ground floor (floor 0)
|
||||||
|
and then follows the instructions one character at a time.
|
||||||
|
|
||||||
|
An opening parenthesis, (, means he should go up one floor, and a closing parenthesis, ), means
|
||||||
|
he should go down one floor.
|
||||||
|
|
||||||
|
The apartment building is very tall, and the basement is very deep; he will never find the top
|
||||||
|
or bottom floors.
|
||||||
|
|
||||||
|
For example:
|
||||||
|
|
||||||
|
• (()) and ()() both result in floor 0.
|
||||||
|
• ((( and (()(()( both result in floor 3.
|
||||||
|
• ))((((( also results in floor 3.
|
||||||
|
• ()) and ))( both result in floor -1 (the first basement level).
|
||||||
|
• ))) and )())()) both result in floor -3.
|
||||||
|
|
||||||
|
To what floor do the instructions take Santa?
|
||||||
|
|
||||||
|
Your puzzle answer was 138.
|
||||||
|
|
||||||
|
--- Part Two ---
|
||||||
|
|
||||||
|
Now, given the same instructions, find the position of the first character that causes him to
|
||||||
|
enter the basement (floor -1). The first character in the instructions has position 1, the
|
||||||
|
second character has position 2, and so on.
|
||||||
|
|
||||||
|
For example:
|
||||||
|
|
||||||
|
• ) causes him to enter the basement at character position 1.
|
||||||
|
• ()()) causes him to enter the basement at character position 5.
|
||||||
|
|
||||||
|
What is the position of the character that causes Santa to first enter the basement?
|
||||||
|
|
||||||
|
Your puzzle answer was 1771.
|
||||||
|
|
||||||
|
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/1/input
|
||||||
|
. https://twitter.com/intent/tweet?text=I%27ve+completed+%22Not+Quite+Lisp%22+%2D+Day+1+%2D+Advent+of+Code&url=http%3A%2F%2Fadventofcode%2Ecom%2Fday%2F1&related=ericwastl&hashtags=AdventOfCode
|
||||||
|
. https://plus.google.com/share?url=http%3A%2F%2Fadventofcode%2Ecom%2Fday%2F1
|
||||||
|
. http://www.reddit.com/submit?url=http%3A%2F%2Fadventofcode%2Ecom%2Fday%2F1&title=I%27ve+completed+%22Not+Quite+Lisp%22+%2D+Day+1+%2D+Advent+of+Code
|
1000
2015/day02/input
Normal file
1000
2015/day02/input
Normal file
File diff suppressed because it is too large
Load Diff
73
2015/day02/main.go
Normal file
73
2015/day02/main.go
Normal file
@ -0,0 +1,73 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"io"
|
||||||
|
"log"
|
||||||
|
"strconv"
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
var input []string
|
||||||
|
var readInp string
|
||||||
|
for {
|
||||||
|
_, err := fmt.Scan(&readInp)
|
||||||
|
if err != nil {
|
||||||
|
if err != io.EOF {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
break
|
||||||
|
}
|
||||||
|
input = append(input, readInp)
|
||||||
|
}
|
||||||
|
var totalPaper, totalRibbon int
|
||||||
|
for _, k := range input {
|
||||||
|
l, w, h := parseInputString(k)
|
||||||
|
totalPaper += calcPaperForPresent(l, w, h)
|
||||||
|
totalRibbon += calcRibbonForPresent(l, w, h)
|
||||||
|
}
|
||||||
|
fmt.Printf("The elves need %d sq ft of wrapping paper\n", totalPaper)
|
||||||
|
fmt.Printf("and %d ft of ribbon.\n", totalRibbon)
|
||||||
|
}
|
||||||
|
|
||||||
|
func parseInputString(inp string) (int, int, int) {
|
||||||
|
dim := strings.Split(inp, "x")
|
||||||
|
if len(dim) == 3 {
|
||||||
|
pt1, _ := strconv.Atoi(dim[0])
|
||||||
|
pt2, _ := strconv.Atoi(dim[1])
|
||||||
|
pt3, _ := strconv.Atoi(dim[2])
|
||||||
|
return pt1, pt2, pt3
|
||||||
|
}
|
||||||
|
return 0, 0, 0
|
||||||
|
}
|
||||||
|
|
||||||
|
func calcPaperForPresent(l, w, h int) int {
|
||||||
|
pt1 := l * w
|
||||||
|
pt2 := w * h
|
||||||
|
pt3 := h * l
|
||||||
|
pt4 := pt3
|
||||||
|
if pt1 < pt2 && pt1 < pt3 {
|
||||||
|
pt4 = pt1
|
||||||
|
} else if pt2 < pt3 {
|
||||||
|
pt4 = pt2
|
||||||
|
}
|
||||||
|
return pt1*2 + pt2*2 + pt3*2 + pt4
|
||||||
|
}
|
||||||
|
|
||||||
|
func calcRibbonForPresent(l, w, h int) int {
|
||||||
|
var low1, low2 int
|
||||||
|
low2 = h
|
||||||
|
if l < w {
|
||||||
|
low1 = l
|
||||||
|
if w < h {
|
||||||
|
low2 = w
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
low1 = w
|
||||||
|
if l < h {
|
||||||
|
low2 = l
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return low1*2 + low2*2 + (l * w * h)
|
||||||
|
}
|
77
2015/day02/problem
Normal file
77
2015/day02/problem
Normal file
@ -0,0 +1,77 @@
|
|||||||
|
Advent of Code
|
||||||
|
|
||||||
|
br0xen 40*
|
||||||
|
|
||||||
|
• [About]
|
||||||
|
• [Stats]
|
||||||
|
• [Leaderboard]
|
||||||
|
• [Settings]
|
||||||
|
• [Log out]
|
||||||
|
|
||||||
|
--- Day 2: I Was Told There Would Be No Math ---
|
||||||
|
|
||||||
|
The elves are running low on wrapping paper, and so they need to submit an order for more. They
|
||||||
|
have a list of the dimensions (length l, width w, and height h) of each present, and only want
|
||||||
|
to order exactly as much as they need.
|
||||||
|
|
||||||
|
Fortunately, every present is a box (a perfect right rectangular prism), which makes
|
||||||
|
calculating the required wrapping paper for each gift a little easier: find the surface area of
|
||||||
|
the box, which is 2*l*w + 2*w*h + 2*h*l. The elves also need a little extra paper for each
|
||||||
|
present: the area of the smallest side.
|
||||||
|
|
||||||
|
For example:
|
||||||
|
|
||||||
|
• A present with dimensions 2x3x4 requires 2*6 + 2*12 + 2*8 = 52 square feet of wrapping
|
||||||
|
paper plus 6 square feet of slack, for a total of 58 square feet.
|
||||||
|
• A present with dimensions 1x1x10 requires 2*1 + 2*10 + 2*10 = 42 square feet of wrapping
|
||||||
|
paper plus 1 square foot of slack, for a total of 43 square feet.
|
||||||
|
|
||||||
|
All numbers in the elves' list are in feet. How many total square feet of wrapping paper should
|
||||||
|
they order?
|
||||||
|
|
||||||
|
Your puzzle answer was 1588178.
|
||||||
|
|
||||||
|
--- Part Two ---
|
||||||
|
|
||||||
|
The elves are also running low on ribbon. Ribbon is all the same width, so they only have to
|
||||||
|
worry about the length they need to order, which they would again like to be exact.
|
||||||
|
|
||||||
|
The ribbon required to wrap a present is the shortest distance around its sides, or the
|
||||||
|
smallest perimeter of any one face. Each present also requires a bow made out of ribbon as
|
||||||
|
well; the feet of ribbon required for the perfect bow is equal to the cubic feet of volume of
|
||||||
|
the present. Don't ask how they tie the bow, though; they'll never tell.
|
||||||
|
|
||||||
|
For example:
|
||||||
|
|
||||||
|
• A present with dimensions 2x3x4 requires 2+2+3+3 = 10 feet of ribbon to wrap the present
|
||||||
|
plus 2*3*4 = 24 feet of ribbon for the bow, for a total of 34 feet.
|
||||||
|
• A present with dimensions 1x1x10 requires 1+1+1+1 = 4 feet of ribbon to wrap the present
|
||||||
|
plus 1*1*10 = 10 feet of ribbon for the bow, for a total of 14 feet.
|
||||||
|
|
||||||
|
How many total feet of ribbon should they order?
|
||||||
|
|
||||||
|
Your puzzle answer was 3783758.
|
||||||
|
|
||||||
|
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
|
||||||
|
. https://en.wikipedia.org/wiki/Cuboid#Rectangular_cuboid
|
||||||
|
. http://adventofcode.com/
|
||||||
|
. http://adventofcode.com/day/2/input
|
||||||
|
. https://twitter.com/intent/tweet?text=I%27ve+completed+%22I+Was+Told+There+Would+Be+No+Math%22+%2D+Day+2+%2D+Advent+of+Code&url=http%3A%2F%2Fadventofcode%2Ecom%2Fday%2F2&related=ericwastl&hashtags=AdventOfCode
|
||||||
|
. https://plus.google.com/share?url=http%3A%2F%2Fadventofcode%2Ecom%2Fday%2F2
|
||||||
|
. http://www.reddit.com/submit?url=http%3A%2F%2Fadventofcode%2Ecom%2Fday%2F2&title=I%27ve+completed+%22I+Was+Told+There+Would+Be+No+Math%22+%2D+Day+2+%2D+Advent+of+Code
|
1
2015/day03/input
Normal file
1
2015/day03/input
Normal file
File diff suppressed because one or more lines are too long
60
2015/day03/main.go
Normal file
60
2015/day03/main.go
Normal file
@ -0,0 +1,60 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"io"
|
||||||
|
"log"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
var input []string
|
||||||
|
var readInp string
|
||||||
|
for {
|
||||||
|
_, err := fmt.Scan(&readInp)
|
||||||
|
if err != nil {
|
||||||
|
if err != io.EOF {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
break
|
||||||
|
}
|
||||||
|
input = append(input, readInp)
|
||||||
|
}
|
||||||
|
|
||||||
|
santaResults := santa(input, 0, 2)
|
||||||
|
santaResults["0;0"] = 1
|
||||||
|
roboResults := santa(input, 1, 2)
|
||||||
|
for i, k := range roboResults {
|
||||||
|
santaResults[i] += k
|
||||||
|
}
|
||||||
|
fmt.Printf("Santa delivered presents to %d houses\n", len(santaResults))
|
||||||
|
}
|
||||||
|
|
||||||
|
func santa(input []string, offset, numWorkers int) map[string]int {
|
||||||
|
var numDir int
|
||||||
|
houses := make(map[string]int)
|
||||||
|
var currX, currY int
|
||||||
|
for _, k := range input {
|
||||||
|
for _, r := range k {
|
||||||
|
if numDir >= offset {
|
||||||
|
if (numDir+offset)%(numWorkers) == 0 {
|
||||||
|
// We've waited, now start visiting
|
||||||
|
switch r {
|
||||||
|
case '^':
|
||||||
|
currY--
|
||||||
|
case '>':
|
||||||
|
currX++
|
||||||
|
case 'v':
|
||||||
|
currY++
|
||||||
|
case '<':
|
||||||
|
currX--
|
||||||
|
}
|
||||||
|
houseCoords := fmt.Sprintf("%d;%d", currX, currY)
|
||||||
|
houses[houseCoords]++
|
||||||
|
}
|
||||||
|
}
|
||||||
|
numDir++
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return houses
|
||||||
|
}
|
75
2015/day03/problem
Normal file
75
2015/day03/problem
Normal file
@ -0,0 +1,75 @@
|
|||||||
|
Advent of Code
|
||||||
|
|
||||||
|
br0xen 40*
|
||||||
|
|
||||||
|
• [About]
|
||||||
|
• [Stats]
|
||||||
|
• [Leaderboard]
|
||||||
|
• [Settings]
|
||||||
|
• [Log out]
|
||||||
|
|
||||||
|
--- Day 3: Perfectly Spherical Houses in a Vacuum ---
|
||||||
|
|
||||||
|
Santa is delivering presents to an infinite two-dimensional grid of houses.
|
||||||
|
|
||||||
|
He begins by delivering a present to the house at his starting location, and then an elf at the
|
||||||
|
North Pole calls him via radio and tells him where to move next. Moves are always exactly one
|
||||||
|
house to the north (^), south (v), east (>), or west (<). After each move, he delivers another
|
||||||
|
present to the house at his new location.
|
||||||
|
|
||||||
|
However, the elf back at the north pole has had a little too much eggnog, and so his directions
|
||||||
|
are a little off, and Santa ends up visiting some houses more than once. How many houses
|
||||||
|
receive at least one present?
|
||||||
|
|
||||||
|
For example:
|
||||||
|
|
||||||
|
• > delivers presents to 2 houses: one at the starting location, and one to the east.
|
||||||
|
• ^>v< delivers presents to 4 houses in a square, including twice to the house at his
|
||||||
|
starting/ending location.
|
||||||
|
• ^v^v^v^v^v delivers a bunch of presents to some very lucky children at only 2 houses.
|
||||||
|
|
||||||
|
Your puzzle answer was 2572.
|
||||||
|
|
||||||
|
--- Part Two ---
|
||||||
|
|
||||||
|
The next year, to speed up the process, Santa creates a robot version of himself, Robo-Santa,
|
||||||
|
to deliver presents with him.
|
||||||
|
|
||||||
|
Santa and Robo-Santa start at the same location (delivering two presents to the same starting
|
||||||
|
house), then take turns moving based on instructions from the elf, who is eggnoggedly reading
|
||||||
|
from the same script as the previous year.
|
||||||
|
|
||||||
|
This year, how many houses receive at least one present?
|
||||||
|
|
||||||
|
For example:
|
||||||
|
|
||||||
|
• ^v delivers presents to 3 houses, because Santa goes north, and then Robo-Santa goes south.
|
||||||
|
• ^>v< now delivers presents to 3 houses, and Santa and Robo-Santa end up back where they
|
||||||
|
started.
|
||||||
|
• ^v^v^v^v^v now delivers presents to 11 houses, with Santa going one direction and
|
||||||
|
Robo-Santa going the other.
|
||||||
|
|
||||||
|
Your puzzle answer was 2631.
|
||||||
|
|
||||||
|
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/3/input
|
||||||
|
. https://twitter.com/intent/tweet?text=I%27ve+completed+%22Perfectly+Spherical+Houses+in+a+Vacuum%22+%2D+Day+3+%2D+Advent+of+Code&url=http%3A%2F%2Fadventofcode%2Ecom%2Fday%2F3&related=ericwastl&hashtags=AdventOfCode
|
||||||
|
. https://plus.google.com/share?url=http%3A%2F%2Fadventofcode%2Ecom%2Fday%2F3
|
||||||
|
. http://www.reddit.com/submit?url=http%3A%2F%2Fadventofcode%2Ecom%2Fday%2F3&title=I%27ve+completed+%22Perfectly+Spherical+Houses+in+a+Vacuum%22+%2D+Day+3+%2D+Advent+of+Code
|
1
2015/day04/input
Normal file
1
2015/day04/input
Normal file
@ -0,0 +1 @@
|
|||||||
|
yzbqklnj
|
48
2015/day04/main.go
Normal file
48
2015/day04/main.go
Normal file
@ -0,0 +1,48 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"crypto/md5"
|
||||||
|
"fmt"
|
||||||
|
"io"
|
||||||
|
"log"
|
||||||
|
"strconv"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
var readInp string
|
||||||
|
for {
|
||||||
|
_, err := fmt.Scan(&readInp)
|
||||||
|
if err != nil {
|
||||||
|
if err != io.EOF {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
firstCoin := searchChunk(readInp, 0, 1000000000)
|
||||||
|
fmt.Printf("\n%s%d :: %d\n", readInp, firstCoin, firstCoin)
|
||||||
|
}
|
||||||
|
|
||||||
|
func searchChunk(key string, start, end int) int {
|
||||||
|
// So we know it's still running
|
||||||
|
for i := start; i <= end; i++ {
|
||||||
|
coin := key + strconv.Itoa(i)
|
||||||
|
coinMd5 := fmt.Sprintf("%x", md5.Sum([]byte(coin)))
|
||||||
|
if isCoin(coinMd5, "000000") {
|
||||||
|
return i
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return -1
|
||||||
|
}
|
||||||
|
|
||||||
|
func isCoin(s string, moneyMaker string) bool {
|
||||||
|
if len(s) < len(moneyMaker) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
for i := 0; i < len(moneyMaker); i++ {
|
||||||
|
if s[i] != moneyMaker[i] {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
}
|
61
2015/day04/problem
Normal file
61
2015/day04/problem
Normal file
@ -0,0 +1,61 @@
|
|||||||
|
Advent of Code
|
||||||
|
|
||||||
|
br0xen 40*
|
||||||
|
|
||||||
|
• [About]
|
||||||
|
• [Stats]
|
||||||
|
• [Leaderboard]
|
||||||
|
• [Settings]
|
||||||
|
• [Log out]
|
||||||
|
|
||||||
|
--- Day 4: The Ideal Stocking Stuffer ---
|
||||||
|
|
||||||
|
Santa needs help mining some AdventCoins (very similar to bitcoins) to use as gifts for all the
|
||||||
|
economically forward-thinking little girls and boys.
|
||||||
|
|
||||||
|
To do this, he needs to find MD5 hashes which, in hexadecimal, start with at least five zeroes.
|
||||||
|
The input to the MD5 hash is some secret key (your puzzle input, given below) followed by a
|
||||||
|
number in decimal. To mine AdventCoins, you must find Santa the lowest positive number (no
|
||||||
|
leading zeroes: 1, 2, 3, ...) that produces such a hash.
|
||||||
|
|
||||||
|
For example:
|
||||||
|
|
||||||
|
• If your secret key is abcdef, the answer is 609043, because the MD5 hash of abcdef609043
|
||||||
|
starts with five zeroes (000001dbbfa...), and it is the lowest such number to do so.
|
||||||
|
• If your secret key is pqrstuv, the lowest number it combines with to make an MD5 hash
|
||||||
|
starting with five zeroes is 1048970; that is, the MD5 hash of pqrstuv1048970 looks like
|
||||||
|
000006136ef....
|
||||||
|
|
||||||
|
Your puzzle answer was 282749.
|
||||||
|
|
||||||
|
--- Part Two ---
|
||||||
|
|
||||||
|
Now find one that starts with six zeroes.
|
||||||
|
|
||||||
|
Your puzzle answer was 9962624.
|
||||||
|
|
||||||
|
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 yzbqklnj.
|
||||||
|
|
||||||
|
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
|
||||||
|
. https://en.wikipedia.org/wiki/Bitcoin#Mining
|
||||||
|
. https://en.wikipedia.org/wiki/Bitcoin
|
||||||
|
. https://en.wikipedia.org/wiki/MD5
|
||||||
|
. https://en.wikipedia.org/wiki/Hexadecimal
|
||||||
|
. http://adventofcode.com/
|
||||||
|
. https://twitter.com/intent/tweet?text=I%27ve+completed+%22The+Ideal+Stocking+Stuffer%22+%2D+Day+4+%2D+Advent+of+Code&url=http%3A%2F%2Fadventofcode%2Ecom%2Fday%2F4&related=ericwastl&hashtags=AdventOfCode
|
||||||
|
. https://plus.google.com/share?url=http%3A%2F%2Fadventofcode%2Ecom%2Fday%2F4
|
||||||
|
. http://www.reddit.com/submit?url=http%3A%2F%2Fadventofcode%2Ecom%2Fday%2F4&title=I%27ve+completed+%22The+Ideal+Stocking+Stuffer%22+%2D+Day+4+%2D+Advent+of+Code
|
1000
2015/day05/input
Normal file
1000
2015/day05/input
Normal file
File diff suppressed because it is too large
Load Diff
82
2015/day05/main.go
Normal file
82
2015/day05/main.go
Normal file
@ -0,0 +1,82 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"io"
|
||||||
|
"log"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
var input []string
|
||||||
|
var readInp string
|
||||||
|
for {
|
||||||
|
_, err := fmt.Scan(&readInp)
|
||||||
|
if err != nil {
|
||||||
|
if err != io.EOF {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
break
|
||||||
|
}
|
||||||
|
input = append(input, readInp)
|
||||||
|
}
|
||||||
|
|
||||||
|
var numNice int
|
||||||
|
for _, k := range input {
|
||||||
|
if isNicePt2(k) {
|
||||||
|
numNice++
|
||||||
|
}
|
||||||
|
}
|
||||||
|
fmt.Printf("There are %d nice strings (out of %d total)\n", numNice, len(input))
|
||||||
|
}
|
||||||
|
|
||||||
|
func isNicePt1(s string) bool {
|
||||||
|
var prev byte
|
||||||
|
var numVowels int
|
||||||
|
var hasDouble bool
|
||||||
|
for i := range s {
|
||||||
|
if s[i] == 'b' && prev == 'a' {
|
||||||
|
return false
|
||||||
|
} else if s[i] == 'd' && prev == 'c' {
|
||||||
|
return false
|
||||||
|
} else if s[i] == 'q' && prev == 'p' {
|
||||||
|
return false
|
||||||
|
} else if s[i] == 'y' && prev == 'x' {
|
||||||
|
return false
|
||||||
|
} else if s[i] == 'a' || s[i] == 'e' || s[i] == 'i' || s[i] == 'o' || s[i] == 'u' {
|
||||||
|
numVowels++
|
||||||
|
}
|
||||||
|
if prev == s[i] {
|
||||||
|
hasDouble = true
|
||||||
|
}
|
||||||
|
prev = s[i]
|
||||||
|
}
|
||||||
|
return (numVowels > 2 && hasDouble)
|
||||||
|
}
|
||||||
|
|
||||||
|
func isNicePt2(s string) bool {
|
||||||
|
var splitRepeat bool
|
||||||
|
var double bool
|
||||||
|
for i := range s {
|
||||||
|
if i > 0 {
|
||||||
|
double = double || hasDouble(s[i-1], s[i], s[i+1:])
|
||||||
|
}
|
||||||
|
if i > 1 {
|
||||||
|
splitRepeat = splitRepeat || (s[i-2] == s[i])
|
||||||
|
}
|
||||||
|
if double && splitRepeat {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
func hasDouble(b1, b2 byte, s string) bool {
|
||||||
|
var prev byte
|
||||||
|
for i := range s {
|
||||||
|
if prev == b1 && s[i] == b2 {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
prev = s[i]
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
85
2015/day05/problem
Normal file
85
2015/day05/problem
Normal file
@ -0,0 +1,85 @@
|
|||||||
|
Advent of Code
|
||||||
|
|
||||||
|
br0xen 40*
|
||||||
|
|
||||||
|
• [About]
|
||||||
|
• [Stats]
|
||||||
|
• [Leaderboard]
|
||||||
|
• [Settings]
|
||||||
|
• [Log out]
|
||||||
|
|
||||||
|
--- Day 5: Doesn't He Have Intern-Elves For This? ---
|
||||||
|
|
||||||
|
Santa needs help figuring out which strings in his text file are naughty or nice.
|
||||||
|
|
||||||
|
A nice string is one with all of the following properties:
|
||||||
|
|
||||||
|
• It contains at least three vowels (aeiou only), like aei, xazegov, or aeiouaeiouaeiou.
|
||||||
|
• It contains at least one letter that appears twice in a row, like xx, abcdde (dd), or
|
||||||
|
aabbccdd (aa, bb, cc, or dd).
|
||||||
|
• It does not contain the strings ab, cd, pq, or xy, even if they are part of one of the
|
||||||
|
other requirements.
|
||||||
|
|
||||||
|
For example:
|
||||||
|
|
||||||
|
• ugknbfddgicrmopn is nice because it has at least three vowels (u...i...o...), a double
|
||||||
|
letter (...dd...), and none of the disallowed substrings.
|
||||||
|
• aaa is nice because it has at least three vowels and a double letter, even though the
|
||||||
|
letters used by different rules overlap.
|
||||||
|
• jchzalrnumimnmhp is naughty because it has no double letter.
|
||||||
|
• haegwjzuvuyypxyu is naughty because it contains the string xy.
|
||||||
|
• dvszwmarrgswjxmb is naughty because it contains only one vowel.
|
||||||
|
|
||||||
|
How many strings are nice?
|
||||||
|
|
||||||
|
Your puzzle answer was 255.
|
||||||
|
|
||||||
|
--- Part Two ---
|
||||||
|
|
||||||
|
Realizing the error of his ways, Santa has switched to a better model of determining whether a
|
||||||
|
string is naughty or nice. None of the old rules apply, as they are all clearly ridiculous.
|
||||||
|
|
||||||
|
Now, a nice string is one with all of the following properties:
|
||||||
|
|
||||||
|
• It contains a pair of any two letters that appears at least twice in the string without
|
||||||
|
overlapping, like xyxy (xy) or aabcdefgaa (aa), but not like aaa (aa, but it overlaps).
|
||||||
|
• It contains at least one letter which repeats with exactly one letter between them, like
|
||||||
|
xyx, abcdefeghi (efe), or even aaa.
|
||||||
|
|
||||||
|
For example:
|
||||||
|
|
||||||
|
• qjhvhtzxzqqjkmpb is nice because is has a pair that appears twice (qj) and a letter that
|
||||||
|
repeats with exactly one letter between them (zxz).
|
||||||
|
• xxyxx is nice because it has a pair that appears twice and a letter that repeats with one
|
||||||
|
between, even though the letters used by each rule overlap.
|
||||||
|
• uurcxstgmygtbstg is naughty because it has a pair (tg) but no repeat with a single letter
|
||||||
|
between them.
|
||||||
|
• ieodomkazucvgmuy is naughty because it has a repeating letter with one between (odo), but
|
||||||
|
no pair that appears twice.
|
||||||
|
|
||||||
|
How many strings are nice under these new rules?
|
||||||
|
|
||||||
|
Your puzzle answer was 55.
|
||||||
|
|
||||||
|
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/5/input
|
||||||
|
. https://twitter.com/intent/tweet?text=I%27ve+completed+%22Doesn%27t+He+Have+Intern%2DElves+For+This%3F%22+%2D+Day+5+%2D+Advent+of+Code&url=http%3A%2F%2Fadventofcode%2Ecom%2Fday%2F5&related=ericwastl&hashtags=AdventOfCode
|
||||||
|
. https://plus.google.com/share?url=http%3A%2F%2Fadventofcode%2Ecom%2Fday%2F5
|
||||||
|
. http://www.reddit.com/submit?url=http%3A%2F%2Fadventofcode%2Ecom%2Fday%2F5&title=I%27ve+completed+%22Doesn%27t+He+Have+Intern%2DElves+For+This%3F%22+%2D+Day+5+%2D+Advent+of+Code
|
300
2015/day06/input
Normal file
300
2015/day06/input
Normal file
@ -0,0 +1,300 @@
|
|||||||
|
turn on 887,9 through 959,629
|
||||||
|
turn on 454,398 through 844,448
|
||||||
|
turn off 539,243 through 559,965
|
||||||
|
turn off 370,819 through 676,868
|
||||||
|
turn off 145,40 through 370,997
|
||||||
|
turn off 301,3 through 808,453
|
||||||
|
turn on 351,678 through 951,908
|
||||||
|
toggle 720,196 through 897,994
|
||||||
|
toggle 831,394 through 904,860
|
||||||
|
toggle 753,664 through 970,926
|
||||||
|
turn off 150,300 through 213,740
|
||||||
|
turn on 141,242 through 932,871
|
||||||
|
toggle 294,259 through 474,326
|
||||||
|
toggle 678,333 through 752,957
|
||||||
|
toggle 393,804 through 510,976
|
||||||
|
turn off 6,964 through 411,976
|
||||||
|
turn off 33,572 through 978,590
|
||||||
|
turn on 579,693 through 650,978
|
||||||
|
turn on 150,20 through 652,719
|
||||||
|
turn off 782,143 through 808,802
|
||||||
|
turn off 240,377 through 761,468
|
||||||
|
turn off 899,828 through 958,967
|
||||||
|
turn on 613,565 through 952,659
|
||||||
|
turn on 295,36 through 964,978
|
||||||
|
toggle 846,296 through 969,528
|
||||||
|
turn off 211,254 through 529,491
|
||||||
|
turn off 231,594 through 406,794
|
||||||
|
turn off 169,791 through 758,942
|
||||||
|
turn on 955,440 through 980,477
|
||||||
|
toggle 944,498 through 995,928
|
||||||
|
turn on 519,391 through 605,718
|
||||||
|
toggle 521,303 through 617,366
|
||||||
|
turn off 524,349 through 694,791
|
||||||
|
toggle 391,87 through 499,792
|
||||||
|
toggle 562,527 through 668,935
|
||||||
|
turn off 68,358 through 857,453
|
||||||
|
toggle 815,811 through 889,828
|
||||||
|
turn off 666,61 through 768,87
|
||||||
|
turn on 27,501 through 921,952
|
||||||
|
turn on 953,102 through 983,471
|
||||||
|
turn on 277,552 through 451,723
|
||||||
|
turn off 64,253 through 655,960
|
||||||
|
turn on 47,485 through 734,977
|
||||||
|
turn off 59,119 through 699,734
|
||||||
|
toggle 407,898 through 493,955
|
||||||
|
toggle 912,966 through 949,991
|
||||||
|
turn on 479,990 through 895,990
|
||||||
|
toggle 390,589 through 869,766
|
||||||
|
toggle 593,903 through 926,943
|
||||||
|
toggle 358,439 through 870,528
|
||||||
|
turn off 649,410 through 652,875
|
||||||
|
turn on 629,834 through 712,895
|
||||||
|
toggle 254,555 through 770,901
|
||||||
|
toggle 641,832 through 947,850
|
||||||
|
turn on 268,448 through 743,777
|
||||||
|
turn off 512,123 through 625,874
|
||||||
|
turn off 498,262 through 930,811
|
||||||
|
turn off 835,158 through 886,242
|
||||||
|
toggle 546,310 through 607,773
|
||||||
|
turn on 501,505 through 896,909
|
||||||
|
turn off 666,796 through 817,924
|
||||||
|
toggle 987,789 through 993,809
|
||||||
|
toggle 745,8 through 860,693
|
||||||
|
toggle 181,983 through 731,988
|
||||||
|
turn on 826,174 through 924,883
|
||||||
|
turn on 239,228 through 843,993
|
||||||
|
turn on 205,613 through 891,667
|
||||||
|
toggle 867,873 through 984,896
|
||||||
|
turn on 628,251 through 677,681
|
||||||
|
toggle 276,956 through 631,964
|
||||||
|
turn on 78,358 through 974,713
|
||||||
|
turn on 521,360 through 773,597
|
||||||
|
turn off 963,52 through 979,502
|
||||||
|
turn on 117,151 through 934,622
|
||||||
|
toggle 237,91 through 528,164
|
||||||
|
turn on 944,269 through 975,453
|
||||||
|
toggle 979,460 through 988,964
|
||||||
|
turn off 440,254 through 681,507
|
||||||
|
toggle 347,100 through 896,785
|
||||||
|
turn off 329,592 through 369,985
|
||||||
|
turn on 931,960 through 979,985
|
||||||
|
toggle 703,3 through 776,36
|
||||||
|
toggle 798,120 through 908,550
|
||||||
|
turn off 186,605 through 914,709
|
||||||
|
turn off 921,725 through 979,956
|
||||||
|
toggle 167,34 through 735,249
|
||||||
|
turn on 726,781 through 987,936
|
||||||
|
toggle 720,336 through 847,756
|
||||||
|
turn on 171,630 through 656,769
|
||||||
|
turn off 417,276 through 751,500
|
||||||
|
toggle 559,485 through 584,534
|
||||||
|
turn on 568,629 through 690,873
|
||||||
|
toggle 248,712 through 277,988
|
||||||
|
toggle 345,594 through 812,723
|
||||||
|
turn off 800,108 through 834,618
|
||||||
|
turn off 967,439 through 986,869
|
||||||
|
turn on 842,209 through 955,529
|
||||||
|
turn on 132,653 through 357,696
|
||||||
|
turn on 817,38 through 973,662
|
||||||
|
turn off 569,816 through 721,861
|
||||||
|
turn on 568,429 through 945,724
|
||||||
|
turn on 77,458 through 844,685
|
||||||
|
turn off 138,78 through 498,851
|
||||||
|
turn on 136,21 through 252,986
|
||||||
|
turn off 2,460 through 863,472
|
||||||
|
turn on 172,81 through 839,332
|
||||||
|
turn on 123,216 through 703,384
|
||||||
|
turn off 879,644 through 944,887
|
||||||
|
toggle 227,491 through 504,793
|
||||||
|
toggle 580,418 through 741,479
|
||||||
|
toggle 65,276 through 414,299
|
||||||
|
toggle 482,486 through 838,931
|
||||||
|
turn off 557,768 through 950,927
|
||||||
|
turn off 615,617 through 955,864
|
||||||
|
turn on 859,886 through 923,919
|
||||||
|
turn on 391,330 through 499,971
|
||||||
|
toggle 521,835 through 613,847
|
||||||
|
turn on 822,787 through 989,847
|
||||||
|
turn on 192,142 through 357,846
|
||||||
|
turn off 564,945 through 985,945
|
||||||
|
turn off 479,361 through 703,799
|
||||||
|
toggle 56,481 through 489,978
|
||||||
|
turn off 632,991 through 774,998
|
||||||
|
toggle 723,526 through 945,792
|
||||||
|
turn on 344,149 through 441,640
|
||||||
|
toggle 568,927 through 624,952
|
||||||
|
turn on 621,784 through 970,788
|
||||||
|
toggle 665,783 through 795,981
|
||||||
|
toggle 386,610 through 817,730
|
||||||
|
toggle 440,399 through 734,417
|
||||||
|
toggle 939,201 through 978,803
|
||||||
|
turn off 395,883 through 554,929
|
||||||
|
turn on 340,309 through 637,561
|
||||||
|
turn off 875,147 through 946,481
|
||||||
|
turn off 945,837 through 957,922
|
||||||
|
turn off 429,982 through 691,991
|
||||||
|
toggle 227,137 through 439,822
|
||||||
|
toggle 4,848 through 7,932
|
||||||
|
turn off 545,146 through 756,943
|
||||||
|
turn on 763,863 through 937,994
|
||||||
|
turn on 232,94 through 404,502
|
||||||
|
turn off 742,254 through 930,512
|
||||||
|
turn on 91,931 through 101,942
|
||||||
|
toggle 585,106 through 651,425
|
||||||
|
turn on 506,700 through 567,960
|
||||||
|
turn off 548,44 through 718,352
|
||||||
|
turn off 194,827 through 673,859
|
||||||
|
turn off 6,645 through 509,764
|
||||||
|
turn off 13,230 through 821,361
|
||||||
|
turn on 734,629 through 919,631
|
||||||
|
toggle 788,552 through 957,972
|
||||||
|
toggle 244,747 through 849,773
|
||||||
|
turn off 162,553 through 276,887
|
||||||
|
turn off 569,577 through 587,604
|
||||||
|
turn off 799,482 through 854,956
|
||||||
|
turn on 744,535 through 909,802
|
||||||
|
toggle 330,641 through 396,986
|
||||||
|
turn off 927,458 through 966,564
|
||||||
|
toggle 984,486 through 986,913
|
||||||
|
toggle 519,682 through 632,708
|
||||||
|
turn on 984,977 through 989,986
|
||||||
|
toggle 766,423 through 934,495
|
||||||
|
turn on 17,509 through 947,718
|
||||||
|
turn on 413,783 through 631,903
|
||||||
|
turn on 482,370 through 493,688
|
||||||
|
turn on 433,859 through 628,938
|
||||||
|
turn off 769,549 through 945,810
|
||||||
|
turn on 178,853 through 539,941
|
||||||
|
turn off 203,251 through 692,433
|
||||||
|
turn off 525,638 through 955,794
|
||||||
|
turn on 169,70 through 764,939
|
||||||
|
toggle 59,352 through 896,404
|
||||||
|
toggle 143,245 through 707,320
|
||||||
|
turn off 103,35 through 160,949
|
||||||
|
toggle 496,24 through 669,507
|
||||||
|
turn off 581,847 through 847,903
|
||||||
|
turn on 689,153 through 733,562
|
||||||
|
turn on 821,487 through 839,699
|
||||||
|
turn on 837,627 through 978,723
|
||||||
|
toggle 96,748 through 973,753
|
||||||
|
toggle 99,818 through 609,995
|
||||||
|
turn on 731,193 through 756,509
|
||||||
|
turn off 622,55 through 813,365
|
||||||
|
turn on 456,490 through 576,548
|
||||||
|
turn on 48,421 through 163,674
|
||||||
|
turn off 853,861 through 924,964
|
||||||
|
turn off 59,963 through 556,987
|
||||||
|
turn on 458,710 through 688,847
|
||||||
|
toggle 12,484 through 878,562
|
||||||
|
turn off 241,964 through 799,983
|
||||||
|
turn off 434,299 through 845,772
|
||||||
|
toggle 896,725 through 956,847
|
||||||
|
turn on 740,289 through 784,345
|
||||||
|
turn off 395,840 through 822,845
|
||||||
|
turn on 955,224 through 996,953
|
||||||
|
turn off 710,186 through 957,722
|
||||||
|
turn off 485,949 through 869,985
|
||||||
|
turn on 848,209 through 975,376
|
||||||
|
toggle 221,241 through 906,384
|
||||||
|
turn on 588,49 through 927,496
|
||||||
|
turn on 273,332 through 735,725
|
||||||
|
turn on 505,962 through 895,962
|
||||||
|
toggle 820,112 through 923,143
|
||||||
|
turn on 919,792 through 978,982
|
||||||
|
toggle 489,461 through 910,737
|
||||||
|
turn off 202,642 through 638,940
|
||||||
|
turn off 708,953 through 970,960
|
||||||
|
toggle 437,291 through 546,381
|
||||||
|
turn on 409,358 through 837,479
|
||||||
|
turn off 756,279 through 870,943
|
||||||
|
turn off 154,657 through 375,703
|
||||||
|
turn off 524,622 through 995,779
|
||||||
|
toggle 514,221 through 651,850
|
||||||
|
toggle 808,464 through 886,646
|
||||||
|
toggle 483,537 through 739,840
|
||||||
|
toggle 654,769 through 831,825
|
||||||
|
turn off 326,37 through 631,69
|
||||||
|
turn off 590,570 through 926,656
|
||||||
|
turn off 881,913 through 911,998
|
||||||
|
turn on 996,102 through 998,616
|
||||||
|
turn off 677,503 through 828,563
|
||||||
|
turn on 860,251 through 877,441
|
||||||
|
turn off 964,100 through 982,377
|
||||||
|
toggle 888,403 through 961,597
|
||||||
|
turn off 632,240 through 938,968
|
||||||
|
toggle 731,176 through 932,413
|
||||||
|
turn on 5,498 through 203,835
|
||||||
|
turn on 819,352 through 929,855
|
||||||
|
toggle 393,813 through 832,816
|
||||||
|
toggle 725,689 through 967,888
|
||||||
|
turn on 968,950 through 969,983
|
||||||
|
turn off 152,628 through 582,896
|
||||||
|
turn off 165,844 through 459,935
|
||||||
|
turn off 882,741 through 974,786
|
||||||
|
turn off 283,179 through 731,899
|
||||||
|
toggle 197,366 through 682,445
|
||||||
|
turn on 106,309 through 120,813
|
||||||
|
toggle 950,387 through 967,782
|
||||||
|
turn off 274,603 through 383,759
|
||||||
|
turn off 155,665 through 284,787
|
||||||
|
toggle 551,871 through 860,962
|
||||||
|
turn off 30,826 through 598,892
|
||||||
|
toggle 76,552 through 977,888
|
||||||
|
turn on 938,180 through 994,997
|
||||||
|
toggle 62,381 through 993,656
|
||||||
|
toggle 625,861 through 921,941
|
||||||
|
turn on 685,311 through 872,521
|
||||||
|
turn on 124,934 through 530,962
|
||||||
|
turn on 606,379 through 961,867
|
||||||
|
turn off 792,735 through 946,783
|
||||||
|
turn on 417,480 through 860,598
|
||||||
|
toggle 178,91 through 481,887
|
||||||
|
turn off 23,935 through 833,962
|
||||||
|
toggle 317,14 through 793,425
|
||||||
|
turn on 986,89 through 999,613
|
||||||
|
turn off 359,201 through 560,554
|
||||||
|
turn off 729,494 through 942,626
|
||||||
|
turn on 204,143 through 876,610
|
||||||
|
toggle 474,97 through 636,542
|
||||||
|
turn off 902,924 through 976,973
|
||||||
|
turn off 389,442 through 824,638
|
||||||
|
turn off 622,863 through 798,863
|
||||||
|
turn on 840,622 through 978,920
|
||||||
|
toggle 567,374 through 925,439
|
||||||
|
turn off 643,319 through 935,662
|
||||||
|
toggle 185,42 through 294,810
|
||||||
|
turn on 47,124 through 598,880
|
||||||
|
toggle 828,303 through 979,770
|
||||||
|
turn off 174,272 through 280,311
|
||||||
|
turn off 540,50 through 880,212
|
||||||
|
turn on 141,994 through 221,998
|
||||||
|
turn on 476,695 through 483,901
|
||||||
|
turn on 960,216 through 972,502
|
||||||
|
toggle 752,335 through 957,733
|
||||||
|
turn off 419,713 through 537,998
|
||||||
|
toggle 772,846 through 994,888
|
||||||
|
turn on 881,159 through 902,312
|
||||||
|
turn off 537,651 through 641,816
|
||||||
|
toggle 561,947 through 638,965
|
||||||
|
turn on 368,458 through 437,612
|
||||||
|
turn on 290,149 through 705,919
|
||||||
|
turn on 711,918 through 974,945
|
||||||
|
toggle 916,242 through 926,786
|
||||||
|
toggle 522,272 through 773,314
|
||||||
|
turn on 432,897 through 440,954
|
||||||
|
turn off 132,169 through 775,380
|
||||||
|
toggle 52,205 through 693,747
|
||||||
|
toggle 926,309 through 976,669
|
||||||
|
turn off 838,342 through 938,444
|
||||||
|
turn on 144,431 through 260,951
|
||||||
|
toggle 780,318 through 975,495
|
||||||
|
turn off 185,412 through 796,541
|
||||||
|
turn on 879,548 through 892,860
|
||||||
|
turn on 294,132 through 460,338
|
||||||
|
turn on 823,500 through 899,529
|
||||||
|
turn off 225,603 through 483,920
|
||||||
|
toggle 717,493 through 930,875
|
||||||
|
toggle 534,948 through 599,968
|
||||||
|
turn on 522,730 through 968,950
|
||||||
|
turn off 102,229 through 674,529
|
70
2015/day06/main.go
Normal file
70
2015/day06/main.go
Normal file
@ -0,0 +1,70 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"io"
|
||||||
|
"log"
|
||||||
|
"os"
|
||||||
|
"strconv"
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
var input []string
|
||||||
|
var readInp string
|
||||||
|
for {
|
||||||
|
_, err := fmt.Scan(&readInp)
|
||||||
|
if err != nil {
|
||||||
|
if err != io.EOF {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
break
|
||||||
|
}
|
||||||
|
input = append(input, readInp)
|
||||||
|
}
|
||||||
|
|
||||||
|
var lights [][]int
|
||||||
|
for i := 0; i < 1000; i++ {
|
||||||
|
lights = append(lights, make([]int, 1000))
|
||||||
|
}
|
||||||
|
for i := range input {
|
||||||
|
if input[i] == "on" || input[i] == "off" || input[i] == "toggle" {
|
||||||
|
stX, stY := parseLocations(input[i+1])
|
||||||
|
endX, endY := parseLocations(input[i+3])
|
||||||
|
for ix := stX; ix <= endX; ix++ {
|
||||||
|
for iy := stY; iy <= endY; iy++ {
|
||||||
|
if input[i] == "on" {
|
||||||
|
lights[ix][iy]++
|
||||||
|
} else if input[i] == "off" {
|
||||||
|
if lights[ix][iy] > 0 {
|
||||||
|
lights[ix][iy]--
|
||||||
|
}
|
||||||
|
} else if input[i] == "toggle" {
|
||||||
|
lights[ix][iy] += 2
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
var brightness int
|
||||||
|
for i := 0; i < 1000; i++ {
|
||||||
|
for j := 0; j < 1000; j++ {
|
||||||
|
brightness += lights[i][j]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
fmt.Printf("Brightness: %d\n", brightness)
|
||||||
|
}
|
||||||
|
|
||||||
|
func parseLocations(s string) (int, int) {
|
||||||
|
dirSplit := strings.Split(s, ",")
|
||||||
|
return assertAtoi(dirSplit[0]), assertAtoi(dirSplit[1])
|
||||||
|
}
|
||||||
|
|
||||||
|
func assertAtoi(s string) int {
|
||||||
|
ret, err := strconv.Atoi(s)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println("Error in Atoi: " + s)
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
return ret
|
||||||
|
}
|
84
2015/day06/problem
Normal file
84
2015/day06/problem
Normal file
@ -0,0 +1,84 @@
|
|||||||
|
Advent of Code
|
||||||
|
|
||||||
|
br0xen 40*
|
||||||
|
|
||||||
|
• [About]
|
||||||
|
• [Stats]
|
||||||
|
• [Leaderboard]
|
||||||
|
• [Settings]
|
||||||
|
• [Log out]
|
||||||
|
|
||||||
|
--- Day 6: Probably a Fire Hazard ---
|
||||||
|
|
||||||
|
Because your neighbors keep defeating you in the holiday house decorating contest year after
|
||||||
|
year, you've decided to deploy one million lights in a 1000x1000 grid.
|
||||||
|
|
||||||
|
Furthermore, because you've been especially nice this year, Santa has mailed you instructions
|
||||||
|
on how to display the ideal lighting configuration.
|
||||||
|
|
||||||
|
Lights in your grid are numbered from 0 to 999 in each direction; the lights at each corner are
|
||||||
|
at 0,0, 0,999, 999,999, and 999,0. The instructions include whether to turn on, turn off, or
|
||||||
|
toggle various inclusive ranges given as coordinate pairs. Each coordinate pair represents
|
||||||
|
opposite corners of a rectangle, inclusive; a coordinate pair like 0,0 through 2,2 therefore
|
||||||
|
refers to 9 lights in a 3x3 square. The lights all start turned off.
|
||||||
|
|
||||||
|
To defeat your neighbors this year, all you have to do is set up your lights by doing the
|
||||||
|
instructions Santa sent you in order.
|
||||||
|
|
||||||
|
For example:
|
||||||
|
|
||||||
|
• turn on 0,0 through 999,999 would turn on (or leave on) every light.
|
||||||
|
• toggle 0,0 through 999,0 would toggle the first line of 1000 lights, turning off the ones
|
||||||
|
that were on, and turning on the ones that were off.
|
||||||
|
• turn off 499,499 through 500,500 would turn off (or leave off) the middle four lights.
|
||||||
|
|
||||||
|
After following the instructions, how many lights are lit?
|
||||||
|
|
||||||
|
Your puzzle answer was 377891.
|
||||||
|
|
||||||
|
--- Part Two ---
|
||||||
|
|
||||||
|
You just finish implementing your winning light pattern when you realize you mistranslated
|
||||||
|
Santa's message from Ancient Nordic Elvish.
|
||||||
|
|
||||||
|
The light grid you bought actually has individual brightness controls; each light can have a
|
||||||
|
brightness of zero or more. The lights all start at zero.
|
||||||
|
|
||||||
|
The phrase turn on actually means that you should increase the brightness of those lights by 1.
|
||||||
|
|
||||||
|
The phrase turn off actually means that you should decrease the brightness of those lights by
|
||||||
|
1, to a minimum of zero.
|
||||||
|
|
||||||
|
The phrase toggle actually means that you should increase the brightness of those lights by 2.
|
||||||
|
|
||||||
|
What is the total brightness of all lights combined after following Santa's instructions?
|
||||||
|
|
||||||
|
For example:
|
||||||
|
|
||||||
|
• turn on 0,0 through 0,0 would increase the total brightness by 1.
|
||||||
|
• toggle 0,0 through 999,999 would increase the total brightness by 2000000.
|
||||||
|
|
||||||
|
Your puzzle answer was 14110788.
|
||||||
|
|
||||||
|
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/6/input
|
||||||
|
. https://twitter.com/intent/tweet?text=I%27ve+completed+%22Probably+a+Fire+Hazard%22+%2D+Day+6+%2D+Advent+of+Code&url=http%3A%2F%2Fadventofcode%2Ecom%2Fday%2F6&related=ericwastl&hashtags=AdventOfCode
|
||||||
|
. https://plus.google.com/share?url=http%3A%2F%2Fadventofcode%2Ecom%2Fday%2F6
|
||||||
|
. http://www.reddit.com/submit?url=http%3A%2F%2Fadventofcode%2Ecom%2Fday%2F6&title=I%27ve+completed+%22Probably+a+Fire+Hazard%22+%2D+Day+6+%2D+Advent+of+Code
|
339
2015/day07/input
Normal file
339
2015/day07/input
Normal file
@ -0,0 +1,339 @@
|
|||||||
|
lf AND lq -> ls
|
||||||
|
iu RSHIFT 1 -> jn
|
||||||
|
bo OR bu -> bv
|
||||||
|
gj RSHIFT 1 -> hc
|
||||||
|
et RSHIFT 2 -> eu
|
||||||
|
bv AND bx -> by
|
||||||
|
is OR it -> iu
|
||||||
|
b OR n -> o
|
||||||
|
gf OR ge -> gg
|
||||||
|
NOT kt -> ku
|
||||||
|
ea AND eb -> ed
|
||||||
|
kl OR kr -> ks
|
||||||
|
hi AND hk -> hl
|
||||||
|
au AND av -> ax
|
||||||
|
lf RSHIFT 2 -> lg
|
||||||
|
dd RSHIFT 3 -> df
|
||||||
|
eu AND fa -> fc
|
||||||
|
df AND dg -> di
|
||||||
|
ip LSHIFT 15 -> it
|
||||||
|
NOT el -> em
|
||||||
|
et OR fe -> ff
|
||||||
|
fj LSHIFT 15 -> fn
|
||||||
|
t OR s -> u
|
||||||
|
ly OR lz -> ma
|
||||||
|
ko AND kq -> kr
|
||||||
|
NOT fx -> fy
|
||||||
|
et RSHIFT 1 -> fm
|
||||||
|
eu OR fa -> fb
|
||||||
|
dd RSHIFT 2 -> de
|
||||||
|
NOT go -> gp
|
||||||
|
kb AND kd -> ke
|
||||||
|
hg OR hh -> hi
|
||||||
|
jm LSHIFT 1 -> kg
|
||||||
|
NOT cn -> co
|
||||||
|
jp RSHIFT 2 -> jq
|
||||||
|
jp RSHIFT 5 -> js
|
||||||
|
1 AND io -> ip
|
||||||
|
eo LSHIFT 15 -> es
|
||||||
|
1 AND jj -> jk
|
||||||
|
g AND i -> j
|
||||||
|
ci RSHIFT 3 -> ck
|
||||||
|
gn AND gp -> gq
|
||||||
|
fs AND fu -> fv
|
||||||
|
lj AND ll -> lm
|
||||||
|
jk LSHIFT 15 -> jo
|
||||||
|
iu RSHIFT 3 -> iw
|
||||||
|
NOT ii -> ij
|
||||||
|
1 AND cc -> cd
|
||||||
|
bn RSHIFT 3 -> bp
|
||||||
|
NOT gw -> gx
|
||||||
|
NOT ft -> fu
|
||||||
|
jn OR jo -> jp
|
||||||
|
iv OR jb -> jc
|
||||||
|
hv OR hu -> hw
|
||||||
|
16076 -> b
|
||||||
|
gj RSHIFT 5 -> gm
|
||||||
|
hq AND hs -> ht
|
||||||
|
dy RSHIFT 1 -> er
|
||||||
|
ao OR an -> ap
|
||||||
|
ld OR le -> lf
|
||||||
|
bk LSHIFT 1 -> ce
|
||||||
|
bz AND cb -> cc
|
||||||
|
bi LSHIFT 15 -> bm
|
||||||
|
il AND in -> io
|
||||||
|
af AND ah -> ai
|
||||||
|
as RSHIFT 1 -> bl
|
||||||
|
lf RSHIFT 3 -> lh
|
||||||
|
er OR es -> et
|
||||||
|
NOT ax -> ay
|
||||||
|
ci RSHIFT 1 -> db
|
||||||
|
et AND fe -> fg
|
||||||
|
lg OR lm -> ln
|
||||||
|
k AND m -> n
|
||||||
|
hz RSHIFT 2 -> ia
|
||||||
|
kh LSHIFT 1 -> lb
|
||||||
|
NOT ey -> ez
|
||||||
|
NOT di -> dj
|
||||||
|
dz OR ef -> eg
|
||||||
|
lx -> a
|
||||||
|
NOT iz -> ja
|
||||||
|
gz LSHIFT 15 -> hd
|
||||||
|
ce OR cd -> cf
|
||||||
|
fq AND fr -> ft
|
||||||
|
at AND az -> bb
|
||||||
|
ha OR gz -> hb
|
||||||
|
fp AND fv -> fx
|
||||||
|
NOT gb -> gc
|
||||||
|
ia AND ig -> ii
|
||||||
|
gl OR gm -> gn
|
||||||
|
0 -> c
|
||||||
|
NOT ca -> cb
|
||||||
|
bn RSHIFT 1 -> cg
|
||||||
|
c LSHIFT 1 -> t
|
||||||
|
iw OR ix -> iy
|
||||||
|
kg OR kf -> kh
|
||||||
|
dy OR ej -> ek
|
||||||
|
km AND kn -> kp
|
||||||
|
NOT fc -> fd
|
||||||
|
hz RSHIFT 3 -> ib
|
||||||
|
NOT dq -> dr
|
||||||
|
NOT fg -> fh
|
||||||
|
dy RSHIFT 2 -> dz
|
||||||
|
kk RSHIFT 2 -> kl
|
||||||
|
1 AND fi -> fj
|
||||||
|
NOT hr -> hs
|
||||||
|
jp RSHIFT 1 -> ki
|
||||||
|
bl OR bm -> bn
|
||||||
|
1 AND gy -> gz
|
||||||
|
gr AND gt -> gu
|
||||||
|
db OR dc -> dd
|
||||||
|
de OR dk -> dl
|
||||||
|
as RSHIFT 5 -> av
|
||||||
|
lf RSHIFT 5 -> li
|
||||||
|
hm AND ho -> hp
|
||||||
|
cg OR ch -> ci
|
||||||
|
gj AND gu -> gw
|
||||||
|
ge LSHIFT 15 -> gi
|
||||||
|
e OR f -> g
|
||||||
|
fp OR fv -> fw
|
||||||
|
fb AND fd -> fe
|
||||||
|
cd LSHIFT 15 -> ch
|
||||||
|
b RSHIFT 1 -> v
|
||||||
|
at OR az -> ba
|
||||||
|
bn RSHIFT 2 -> bo
|
||||||
|
lh AND li -> lk
|
||||||
|
dl AND dn -> do
|
||||||
|
eg AND ei -> ej
|
||||||
|
ex AND ez -> fa
|
||||||
|
NOT kp -> kq
|
||||||
|
NOT lk -> ll
|
||||||
|
x AND ai -> ak
|
||||||
|
jp OR ka -> kb
|
||||||
|
NOT jd -> je
|
||||||
|
iy AND ja -> jb
|
||||||
|
jp RSHIFT 3 -> jr
|
||||||
|
fo OR fz -> ga
|
||||||
|
df OR dg -> dh
|
||||||
|
gj RSHIFT 2 -> gk
|
||||||
|
gj OR gu -> gv
|
||||||
|
NOT jh -> ji
|
||||||
|
ap LSHIFT 1 -> bj
|
||||||
|
NOT ls -> lt
|
||||||
|
ir LSHIFT 1 -> jl
|
||||||
|
bn AND by -> ca
|
||||||
|
lv LSHIFT 15 -> lz
|
||||||
|
ba AND bc -> bd
|
||||||
|
cy LSHIFT 15 -> dc
|
||||||
|
ln AND lp -> lq
|
||||||
|
x RSHIFT 1 -> aq
|
||||||
|
gk OR gq -> gr
|
||||||
|
NOT kx -> ky
|
||||||
|
jg AND ji -> jj
|
||||||
|
bn OR by -> bz
|
||||||
|
fl LSHIFT 1 -> gf
|
||||||
|
bp OR bq -> br
|
||||||
|
he OR hp -> hq
|
||||||
|
et RSHIFT 5 -> ew
|
||||||
|
iu RSHIFT 2 -> iv
|
||||||
|
gl AND gm -> go
|
||||||
|
x OR ai -> aj
|
||||||
|
hc OR hd -> he
|
||||||
|
lg AND lm -> lo
|
||||||
|
lh OR li -> lj
|
||||||
|
da LSHIFT 1 -> du
|
||||||
|
fo RSHIFT 2 -> fp
|
||||||
|
gk AND gq -> gs
|
||||||
|
bj OR bi -> bk
|
||||||
|
lf OR lq -> lr
|
||||||
|
cj AND cp -> cr
|
||||||
|
hu LSHIFT 15 -> hy
|
||||||
|
1 AND bh -> bi
|
||||||
|
fo RSHIFT 3 -> fq
|
||||||
|
NOT lo -> lp
|
||||||
|
hw LSHIFT 1 -> iq
|
||||||
|
dd RSHIFT 1 -> dw
|
||||||
|
dt LSHIFT 15 -> dx
|
||||||
|
dy AND ej -> el
|
||||||
|
an LSHIFT 15 -> ar
|
||||||
|
aq OR ar -> as
|
||||||
|
1 AND r -> s
|
||||||
|
fw AND fy -> fz
|
||||||
|
NOT im -> in
|
||||||
|
et RSHIFT 3 -> ev
|
||||||
|
1 AND ds -> dt
|
||||||
|
ec AND ee -> ef
|
||||||
|
NOT ak -> al
|
||||||
|
jl OR jk -> jm
|
||||||
|
1 AND en -> eo
|
||||||
|
lb OR la -> lc
|
||||||
|
iu AND jf -> jh
|
||||||
|
iu RSHIFT 5 -> ix
|
||||||
|
bo AND bu -> bw
|
||||||
|
cz OR cy -> da
|
||||||
|
iv AND jb -> jd
|
||||||
|
iw AND ix -> iz
|
||||||
|
lf RSHIFT 1 -> ly
|
||||||
|
iu OR jf -> jg
|
||||||
|
NOT dm -> dn
|
||||||
|
lw OR lv -> lx
|
||||||
|
gg LSHIFT 1 -> ha
|
||||||
|
lr AND lt -> lu
|
||||||
|
fm OR fn -> fo
|
||||||
|
he RSHIFT 3 -> hg
|
||||||
|
aj AND al -> am
|
||||||
|
1 AND kz -> la
|
||||||
|
dy RSHIFT 5 -> eb
|
||||||
|
jc AND je -> jf
|
||||||
|
cm AND co -> cp
|
||||||
|
gv AND gx -> gy
|
||||||
|
ev OR ew -> ex
|
||||||
|
jp AND ka -> kc
|
||||||
|
fk OR fj -> fl
|
||||||
|
dy RSHIFT 3 -> ea
|
||||||
|
NOT bs -> bt
|
||||||
|
NOT ag -> ah
|
||||||
|
dz AND ef -> eh
|
||||||
|
cf LSHIFT 1 -> cz
|
||||||
|
NOT cv -> cw
|
||||||
|
1 AND cx -> cy
|
||||||
|
de AND dk -> dm
|
||||||
|
ck AND cl -> cn
|
||||||
|
x RSHIFT 5 -> aa
|
||||||
|
dv LSHIFT 1 -> ep
|
||||||
|
he RSHIFT 2 -> hf
|
||||||
|
NOT bw -> bx
|
||||||
|
ck OR cl -> cm
|
||||||
|
bp AND bq -> bs
|
||||||
|
as OR bd -> be
|
||||||
|
he AND hp -> hr
|
||||||
|
ev AND ew -> ey
|
||||||
|
1 AND lu -> lv
|
||||||
|
kk RSHIFT 3 -> km
|
||||||
|
b AND n -> p
|
||||||
|
NOT kc -> kd
|
||||||
|
lc LSHIFT 1 -> lw
|
||||||
|
km OR kn -> ko
|
||||||
|
id AND if -> ig
|
||||||
|
ih AND ij -> ik
|
||||||
|
jr AND js -> ju
|
||||||
|
ci RSHIFT 5 -> cl
|
||||||
|
hz RSHIFT 1 -> is
|
||||||
|
1 AND ke -> kf
|
||||||
|
NOT gs -> gt
|
||||||
|
aw AND ay -> az
|
||||||
|
x RSHIFT 2 -> y
|
||||||
|
ab AND ad -> ae
|
||||||
|
ff AND fh -> fi
|
||||||
|
ci AND ct -> cv
|
||||||
|
eq LSHIFT 1 -> fk
|
||||||
|
gj RSHIFT 3 -> gl
|
||||||
|
u LSHIFT 1 -> ao
|
||||||
|
NOT bb -> bc
|
||||||
|
NOT hj -> hk
|
||||||
|
kw AND ky -> kz
|
||||||
|
as AND bd -> bf
|
||||||
|
dw OR dx -> dy
|
||||||
|
br AND bt -> bu
|
||||||
|
kk AND kv -> kx
|
||||||
|
ep OR eo -> eq
|
||||||
|
he RSHIFT 1 -> hx
|
||||||
|
ki OR kj -> kk
|
||||||
|
NOT ju -> jv
|
||||||
|
ek AND em -> en
|
||||||
|
kk RSHIFT 5 -> kn
|
||||||
|
NOT eh -> ei
|
||||||
|
hx OR hy -> hz
|
||||||
|
ea OR eb -> ec
|
||||||
|
s LSHIFT 15 -> w
|
||||||
|
fo RSHIFT 1 -> gh
|
||||||
|
kk OR kv -> kw
|
||||||
|
bn RSHIFT 5 -> bq
|
||||||
|
NOT ed -> ee
|
||||||
|
1 AND ht -> hu
|
||||||
|
cu AND cw -> cx
|
||||||
|
b RSHIFT 5 -> f
|
||||||
|
kl AND kr -> kt
|
||||||
|
iq OR ip -> ir
|
||||||
|
ci RSHIFT 2 -> cj
|
||||||
|
cj OR cp -> cq
|
||||||
|
o AND q -> r
|
||||||
|
dd RSHIFT 5 -> dg
|
||||||
|
b RSHIFT 2 -> d
|
||||||
|
ks AND ku -> kv
|
||||||
|
b RSHIFT 3 -> e
|
||||||
|
d OR j -> k
|
||||||
|
NOT p -> q
|
||||||
|
NOT cr -> cs
|
||||||
|
du OR dt -> dv
|
||||||
|
kf LSHIFT 15 -> kj
|
||||||
|
NOT ac -> ad
|
||||||
|
fo RSHIFT 5 -> fr
|
||||||
|
hz OR ik -> il
|
||||||
|
jx AND jz -> ka
|
||||||
|
gh OR gi -> gj
|
||||||
|
kk RSHIFT 1 -> ld
|
||||||
|
hz RSHIFT 5 -> ic
|
||||||
|
as RSHIFT 2 -> at
|
||||||
|
NOT jy -> jz
|
||||||
|
1 AND am -> an
|
||||||
|
ci OR ct -> cu
|
||||||
|
hg AND hh -> hj
|
||||||
|
jq OR jw -> jx
|
||||||
|
v OR w -> x
|
||||||
|
la LSHIFT 15 -> le
|
||||||
|
dh AND dj -> dk
|
||||||
|
dp AND dr -> ds
|
||||||
|
jq AND jw -> jy
|
||||||
|
au OR av -> aw
|
||||||
|
NOT bf -> bg
|
||||||
|
z OR aa -> ab
|
||||||
|
ga AND gc -> gd
|
||||||
|
hz AND ik -> im
|
||||||
|
jt AND jv -> jw
|
||||||
|
z AND aa -> ac
|
||||||
|
jr OR js -> jt
|
||||||
|
hb LSHIFT 1 -> hv
|
||||||
|
hf OR hl -> hm
|
||||||
|
ib OR ic -> id
|
||||||
|
fq OR fr -> fs
|
||||||
|
cq AND cs -> ct
|
||||||
|
ia OR ig -> ih
|
||||||
|
dd OR do -> dp
|
||||||
|
d AND j -> l
|
||||||
|
ib AND ic -> ie
|
||||||
|
as RSHIFT 3 -> au
|
||||||
|
be AND bg -> bh
|
||||||
|
dd AND do -> dq
|
||||||
|
NOT l -> m
|
||||||
|
1 AND gd -> ge
|
||||||
|
y AND ae -> ag
|
||||||
|
fo AND fz -> gb
|
||||||
|
NOT ie -> if
|
||||||
|
e AND f -> h
|
||||||
|
x RSHIFT 3 -> z
|
||||||
|
y OR ae -> af
|
||||||
|
hf AND hl -> hn
|
||||||
|
NOT h -> i
|
||||||
|
NOT hn -> ho
|
||||||
|
he RSHIFT 5 -> hh
|
114
2015/day07/main.go
Normal file
114
2015/day07/main.go
Normal file
@ -0,0 +1,114 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"io"
|
||||||
|
"log"
|
||||||
|
"strconv"
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
|
var wires map[string]uint16
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
var input []string
|
||||||
|
var bldInput string
|
||||||
|
var readInp string
|
||||||
|
for {
|
||||||
|
_, err := fmt.Scan(&readInp)
|
||||||
|
if err != nil {
|
||||||
|
if err != io.EOF {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
break
|
||||||
|
}
|
||||||
|
if strings.HasSuffix(bldInput, "->") {
|
||||||
|
bldInput = bldInput + " " + readInp
|
||||||
|
input = append(input, bldInput)
|
||||||
|
bldInput = ""
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if len(bldInput) > 0 {
|
||||||
|
bldInput += " "
|
||||||
|
}
|
||||||
|
bldInput = bldInput + readInp
|
||||||
|
}
|
||||||
|
|
||||||
|
wires = make(map[string]uint16)
|
||||||
|
var done bool
|
||||||
|
for !done {
|
||||||
|
for i := range input {
|
||||||
|
parsePts := strings.Split(input[i], " -> ")
|
||||||
|
inputs := parsePts[0]
|
||||||
|
output := parsePts[1]
|
||||||
|
if _, ok := getValue(output); ok {
|
||||||
|
// We've already done this one
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
// What's up with these inputs?
|
||||||
|
inpParts := strings.Split(inputs, " ")
|
||||||
|
if len(inpParts) == 1 {
|
||||||
|
if val, ok := getValue(inpParts[0]); ok {
|
||||||
|
setValue(output, val)
|
||||||
|
} else {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
} else if len(inpParts) == 2 {
|
||||||
|
if val, ok := getValue(inpParts[1]); ok {
|
||||||
|
setValue(output, ^val)
|
||||||
|
} else {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// All other gates
|
||||||
|
var inp1, inp2 uint16
|
||||||
|
if val, ok := getValue(inpParts[0]); ok {
|
||||||
|
inp1 = val
|
||||||
|
} else {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if val, ok := getValue(inpParts[2]); ok {
|
||||||
|
inp2 = val
|
||||||
|
} else {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
if inpParts[1] == "RSHIFT" {
|
||||||
|
setValue(output, (inp1 >> inp2))
|
||||||
|
} else if inpParts[1] == "LSHIFT" {
|
||||||
|
setValue(output, (inp1 << inp2))
|
||||||
|
} else if inpParts[1] == "OR" {
|
||||||
|
setValue(output, (inp1 | inp2))
|
||||||
|
} else if inpParts[1] == "AND" {
|
||||||
|
setValue(output, (inp1 & inp2))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if len(wires) == len(input) {
|
||||||
|
done = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if aWire, ok := wires["a"]; ok {
|
||||||
|
fmt.Printf("\"a\" value: %d\n", aWire)
|
||||||
|
done = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func setValue(key string, val uint16) {
|
||||||
|
wires[key] = val
|
||||||
|
}
|
||||||
|
|
||||||
|
func getValue(input string) (uint16, bool) {
|
||||||
|
var ret uint16
|
||||||
|
var i int
|
||||||
|
var err error
|
||||||
|
if i, err = strconv.Atoi(input); err != nil {
|
||||||
|
if w, ok := wires[input]; ok {
|
||||||
|
return w, true
|
||||||
|
}
|
||||||
|
return wires[input], false
|
||||||
|
}
|
||||||
|
ret = uint16(i)
|
||||||
|
return ret, true
|
||||||
|
}
|
103
2015/day07/problem
Normal file
103
2015/day07/problem
Normal file
@ -0,0 +1,103 @@
|
|||||||
|
Advent of Code
|
||||||
|
|
||||||
|
br0xen 40*
|
||||||
|
|
||||||
|
• [About]
|
||||||
|
• [Stats]
|
||||||
|
• [Leaderboard]
|
||||||
|
• [Settings]
|
||||||
|
• [Log out]
|
||||||
|
|
||||||
|
--- Day 7: Some Assembly Required ---
|
||||||
|
|
||||||
|
This year, Santa brought little Bobby Tables a set of wires and bitwise logic gates!
|
||||||
|
Unfortunately, little Bobby is a little under the recommended age range, and he needs help
|
||||||
|
assembling the circuit.
|
||||||
|
|
||||||
|
Each wire has an identifier (some lowercase letters) and can carry a 16-bit signal (a number
|
||||||
|
from 0 to 65535). A signal is provided to each wire by a gate, another wire, or some specific
|
||||||
|
value. Each wire can only get a signal from one source, but can provide its signal to multiple
|
||||||
|
destinations. A gate provides no signal until all of its inputs have a signal.
|
||||||
|
|
||||||
|
The included instructions booklet describes how to connect the parts together: x AND y -> z
|
||||||
|
means to connect wires x and y to an AND gate, and then connect its output to wire z.
|
||||||
|
|
||||||
|
For example:
|
||||||
|
|
||||||
|
• 123 -> x means that the signal 123 is provided to wire x.
|
||||||
|
• x AND y -> z means that the bitwise AND of wire x and wire y is provided to wire z.
|
||||||
|
• p LSHIFT 2 -> q means that the value from wire p is left-shifted by 2 and then provided to
|
||||||
|
wire q.
|
||||||
|
• NOT e -> f means that the bitwise complement of the value from wire e is provided to wire
|
||||||
|
f.
|
||||||
|
|
||||||
|
Other possible gates include OR (bitwise OR) and RSHIFT (right-shift). If, for some reason,
|
||||||
|
you'd like to emulate the circuit instead, almost all programming languages (for example, C,
|
||||||
|
JavaScript, or Python) provide operators for these gates.
|
||||||
|
|
||||||
|
For example, here is a simple circuit:
|
||||||
|
|
||||||
|
123 -> x
|
||||||
|
456 -> y
|
||||||
|
x AND y -> d
|
||||||
|
x OR y -> e
|
||||||
|
x LSHIFT 2 -> f
|
||||||
|
y RSHIFT 2 -> g
|
||||||
|
NOT x -> h
|
||||||
|
NOT y -> i
|
||||||
|
|
||||||
|
After it is run, these are the signals on the wires:
|
||||||
|
|
||||||
|
d: 72
|
||||||
|
e: 507
|
||||||
|
f: 492
|
||||||
|
g: 114
|
||||||
|
h: 65412
|
||||||
|
i: 65079
|
||||||
|
x: 123
|
||||||
|
y: 456
|
||||||
|
|
||||||
|
In little Bobby's kit's instructions booklet (provided as your puzzle input), what signal is
|
||||||
|
ultimately provided to wire a?
|
||||||
|
|
||||||
|
Your puzzle answer was 16076.
|
||||||
|
|
||||||
|
--- Part Two ---
|
||||||
|
|
||||||
|
Now, take the signal you got on wire a, override wire b to that signal, and reset the other
|
||||||
|
wires (including wire a). What new signal is ultimately provided to wire a?
|
||||||
|
|
||||||
|
Your puzzle answer was 2797.
|
||||||
|
|
||||||
|
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
|
||||||
|
. https://en.wikipedia.org/wiki/Bitwise_operation
|
||||||
|
. https://en.wikipedia.org/wiki/16-bit
|
||||||
|
. https://en.wikipedia.org/wiki/Bitwise_operation#AND
|
||||||
|
. https://en.wikipedia.org/wiki/Logical_shift
|
||||||
|
. https://en.wikipedia.org/wiki/Bitwise_operation#NOT
|
||||||
|
. https://en.wikipedia.org/wiki/Bitwise_operation#OR
|
||||||
|
. https://en.wikipedia.org/wiki/Logical_shift
|
||||||
|
. https://en.wikipedia.org/wiki/Bitwise_operations_in_C
|
||||||
|
. https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Bitwise_Operators
|
||||||
|
. https://wiki.python.org/moin/BitwiseOperators
|
||||||
|
. http://adventofcode.com/
|
||||||
|
. http://adventofcode.com/day/7/input
|
||||||
|
. https://twitter.com/intent/tweet?text=I%27ve+completed+%22Some+Assembly+Required%22+%2D+Day+7+%2D+Advent+of+Code&url=http%3A%2F%2Fadventofcode%2Ecom%2Fday%2F7&related=ericwastl&hashtags=AdventOfCode
|
||||||
|
. https://plus.google.com/share?url=http%3A%2F%2Fadventofcode%2Ecom%2Fday%2F7
|
||||||
|
. http://www.reddit.com/submit?url=http%3A%2F%2Fadventofcode%2Ecom%2Fday%2F7&title=I%27ve+completed+%22Some+Assembly+Required%22+%2D+Day+7+%2D+Advent+of+Code
|
300
2015/day08/input
Normal file
300
2015/day08/input
Normal file
@ -0,0 +1,300 @@
|
|||||||
|
"qxfcsmh"
|
||||||
|
"ffsfyxbyuhqkpwatkjgudo"
|
||||||
|
"byc\x9dyxuafof\\\xa6uf\\axfozomj\\olh\x6a"
|
||||||
|
"jtqvz"
|
||||||
|
"uzezxa\"jgbmojtwyfbfguz"
|
||||||
|
"vqsremfk\x8fxiknektafj"
|
||||||
|
"wzntebpxnnt\"vqndz\"i\x47vvjqo\""
|
||||||
|
"higvez\"k\"riewqk"
|
||||||
|
"dlkrbhbrlfrp\\damiauyucwhty"
|
||||||
|
"d\""
|
||||||
|
"qlz"
|
||||||
|
"ku"
|
||||||
|
"yy\"\"uoao\"uripabop"
|
||||||
|
"saduyrntuswlnlkuppdro\\sicxosted"
|
||||||
|
"tj"
|
||||||
|
"zzphopswlwdhebwkxeurvizdv"
|
||||||
|
"xfoheirjoakrpofles\"nfu"
|
||||||
|
"q\xb7oh\"p\xce\"n"
|
||||||
|
"qeendp\"ercwgywdjeylxcv"
|
||||||
|
"dcmem"
|
||||||
|
"\"i\x13r\"l"
|
||||||
|
"ikso\xdcbvqnbrjduh\"uqudzki\xderwk"
|
||||||
|
"wfdsn"
|
||||||
|
"pwynglklryhtsqbno"
|
||||||
|
"hcoj\x63iccz\"v\"ttr"
|
||||||
|
"zf\x23\\hlj\\kkce\\d\\asy\"yyfestwcdxyfj"
|
||||||
|
"xs"
|
||||||
|
"m\"tvltapxdvtrxiy"
|
||||||
|
"bmud"
|
||||||
|
"k\"a"
|
||||||
|
"b\"oas"
|
||||||
|
"\"yexnjjupoqsxyqnquy\"uzfdvetqrc"
|
||||||
|
"vdw\xe3olxfgujaj"
|
||||||
|
"qomcxdnd\"\\cfoe\""
|
||||||
|
"fpul"
|
||||||
|
"m\"avamefphkpv"
|
||||||
|
"vvdnb\\x\\uhnxfw\"dpubfkxfmeuhnxisd"
|
||||||
|
"hey\\"
|
||||||
|
"ldaeigghlfey"
|
||||||
|
"eure\"hoy\xa5iezjp\\tm"
|
||||||
|
"yygb\"twbj\\r\"\x10gmxuhmp\""
|
||||||
|
"weirebp\x39mqonbtmfmd"
|
||||||
|
"ltuz\\hs\"e"
|
||||||
|
"ysvmpc"
|
||||||
|
"g\x8amjtt\"megl\"omsaihifwa"
|
||||||
|
"yimmm"
|
||||||
|
"iiyqfalh"
|
||||||
|
"cwknlaaf"
|
||||||
|
"q\x37feg\xc6s\"xx"
|
||||||
|
"uayrgeurgyp\\oi"
|
||||||
|
"xhug\"pt\"axugllbdiggzhvy"
|
||||||
|
"kdaarqmsjfx\xc3d"
|
||||||
|
"\"vkwla"
|
||||||
|
"d\""
|
||||||
|
"tmroz\"bvfinxoe\\mum\"wmm"
|
||||||
|
"\"n\"bbswxne\\p\\yr\"qhwpdd"
|
||||||
|
"skzlkietklkqovjhvj\xfe"
|
||||||
|
"pbg\\pab\"bubqaf\"obzcwxwywbs\\dhtq"
|
||||||
|
"xxjidvqh\"lx\\wu\"ij"
|
||||||
|
"daef\x5fe\x5b\\kbeeb\x13qnydtboof"
|
||||||
|
"ogvazaqy\"j\x73"
|
||||||
|
"y"
|
||||||
|
"n\"tibetedldy\\gsamm\"nwu"
|
||||||
|
"wldkvgdtqulwkad"
|
||||||
|
"dpmxnj"
|
||||||
|
"twybw\"cdvf\"mjdajurokbce"
|
||||||
|
"ru\"\\lasij\"i"
|
||||||
|
"roc\\vra\\lhrm"
|
||||||
|
"pbkt\x60booz\"fjlkc"
|
||||||
|
"j\x4dytvjwrzt"
|
||||||
|
"\\uiwjkniumxcs"
|
||||||
|
"cbhm\"nexccior\"v\"j\"nazxilmfp\x47"
|
||||||
|
"qdxngevzrlgoq"
|
||||||
|
"\"lrzxftytpobsdfyrtdqpjbpuwmm\x9e"
|
||||||
|
"mdag\x0asnck\xc2ggj\"slb\"fjy"
|
||||||
|
"wyqkhjuazdtcgkcxvjkpnjdae"
|
||||||
|
"aixfk\xc0iom\x21vueob"
|
||||||
|
"dkiiakyjpkffqlluhaetires"
|
||||||
|
"ysspv\"lysgkvnmwbbsy"
|
||||||
|
"gy\"ryexcjjxdm\"xswssgtr"
|
||||||
|
"s"
|
||||||
|
"ddxv"
|
||||||
|
"qwt\"\x27puilb\"pslmbrsxhrz"
|
||||||
|
"qdg\xc9e\\qwtknlvkol\x54oqvmchn\\"
|
||||||
|
"lvo"
|
||||||
|
"b"
|
||||||
|
"fk\"aa\"\"yenwch\\\\on"
|
||||||
|
"srig\x63hpwaavs\\\x80qzk\"xa\"\xe6u\\wr"
|
||||||
|
"yxjxuj\"ghyhhxfj\"\xa6qvatre"
|
||||||
|
"yoktqxjxkzrklkoeroil"
|
||||||
|
"\"jfmik\""
|
||||||
|
"smgseztzdwldikbqrh\""
|
||||||
|
"jftahgctf\"hoqy"
|
||||||
|
"tcnhicr\"znpgckt\"ble"
|
||||||
|
"vqktnkodh\"lo\"a\\bkmdjqqnsqr"
|
||||||
|
"ztnirfzqq"
|
||||||
|
"s"
|
||||||
|
"xx"
|
||||||
|
"iqj\"y\\hqgzflwrdsusasekyrxbp\\ad"
|
||||||
|
"\\xzjhlaiynkioz\"\"bxepzimvgwt"
|
||||||
|
"s\x36rbw"
|
||||||
|
"mniieztwrisvdx"
|
||||||
|
"atyfxioy\x2b\\"
|
||||||
|
"irde\x85\x5cvbah\\jekw\"ia"
|
||||||
|
"bdmftlhkwrprmpat\"prfaocvp"
|
||||||
|
"w\\k"
|
||||||
|
"umbpausy"
|
||||||
|
"zfauhpsangy"
|
||||||
|
"p\"zqyw"
|
||||||
|
"wtztypyqvnnxzvlvipnq\"zu"
|
||||||
|
"deicgwq\\oqvajpbov\\or\"kgplwu"
|
||||||
|
"mbzlfgpi\\\\zqcidjpzqdzxityxa"
|
||||||
|
"lfkxvhma"
|
||||||
|
"\xf2yduqzqr\"\\fak\"p\"n"
|
||||||
|
"mpajacfuxotonpadvng"
|
||||||
|
"anb\\telzvcdu\\a\xf2flfq"
|
||||||
|
"lrs\"ebethwpmuuc\"\x86ygr"
|
||||||
|
"qmvdbhtumzc\"ci"
|
||||||
|
"meet"
|
||||||
|
"yopg\x0fdxdq\"h\\ugsu\xffmolxjv"
|
||||||
|
"uhy"
|
||||||
|
"fzgidrtzycsireghazscvmwcfmw\\t"
|
||||||
|
"cqohkhpgvpru"
|
||||||
|
"bihyigtnvmevx\"xx"
|
||||||
|
"xz"
|
||||||
|
"zofomwotzuxsjk\"q\"mc\"js\"dnmalhxd"
|
||||||
|
"\\ktnddux\\fqvt\"ibnjntjcbn"
|
||||||
|
"ia"
|
||||||
|
"htjadnefwetyp\xd5kbrwfycbyy"
|
||||||
|
"\"\\hkuxqddnao"
|
||||||
|
"meqqsz\x83luecpgaem"
|
||||||
|
"cvks\x87frvxo\"svqivqsdpgwhukmju"
|
||||||
|
"sgmxiai\\o\"riufxwjfigr\xdf"
|
||||||
|
"fgywdfecqufccpcdn"
|
||||||
|
"faghjoq\x28abxnpxj"
|
||||||
|
"zuppgzcfb\"dctvp\"elup\"zxkopx"
|
||||||
|
"xqs\x45xxdqcihbwghmzoa"
|
||||||
|
"anbnlp\\cgcvm\"hc"
|
||||||
|
"xf\"fgrngwzys"
|
||||||
|
"nrxsjduedcy\x24"
|
||||||
|
"\x71sxl\"gj\"sds\"ulcruguz\\t\\ssvjcwhi"
|
||||||
|
"jhj\"msch"
|
||||||
|
"qpovolktfwyiuyicbfeeju\x01"
|
||||||
|
"nkyxmb\"qyqultgt\"nmvzvvnxnb"
|
||||||
|
"ycsrkbstgzqb\"uv\\cisn"
|
||||||
|
"s"
|
||||||
|
"ueptjnn\"\"sh"
|
||||||
|
"lp\"z\"d\"mxtxiy"
|
||||||
|
"yzjtvockdnvbubqabjourf\"k\"uoxwle"
|
||||||
|
"\x82\"wqm\""
|
||||||
|
"\xb5cwtuks\x5fpgh"
|
||||||
|
"wd"
|
||||||
|
"tbvf"
|
||||||
|
"ttbmzdgn"
|
||||||
|
"vfpiyfdejyrlbgcdtwzbnm"
|
||||||
|
"uc"
|
||||||
|
"otdcmhpjagqix"
|
||||||
|
"\\\xb1qso\"s"
|
||||||
|
"scowax"
|
||||||
|
"behpstjdh\xccqlgnqjyz\"eesn"
|
||||||
|
"r\xe1cbnjwzveoomkzlo\\kxlfouhm"
|
||||||
|
"jgrl"
|
||||||
|
"kzqs\\r"
|
||||||
|
"ctscb\x7fthwkdyko\"\x62pkf\"d\xe6knmhurg"
|
||||||
|
"tc\"kw\x3ftt"
|
||||||
|
"bxb\x5ccl"
|
||||||
|
"jyrmfbphsldwpq"
|
||||||
|
"jylpvysl\"\"juducjg"
|
||||||
|
"en\\m\"kxpq\"wpb\\\""
|
||||||
|
"madouht\"bmdwvnyqvpnawiphgac\""
|
||||||
|
"vuxpk\"ltucrw"
|
||||||
|
"aae\x60arr"
|
||||||
|
"ttitnne\"kilkrgssnr\xfdurzh"
|
||||||
|
"oalw"
|
||||||
|
"pc\"\"gktkdykzbdpkwigucqni\"nxiqx"
|
||||||
|
"dbrsaj"
|
||||||
|
"bgzsowyxcbrvhtvekhsh\"qgd"
|
||||||
|
"kudfemvk\"\"\"hkbrbil\"chkqoa"
|
||||||
|
"zjzgj\\ekbhyfzufy"
|
||||||
|
"\\acos\"fqekuxqzxbmkbnn\x1ejzwrm"
|
||||||
|
"elxahvudn\"txtmomotgw"
|
||||||
|
"\x2eoxmwdhelpr\"cgi\xf7pzvb"
|
||||||
|
"eapheklx"
|
||||||
|
"hfvma\"mietvc\"tszbbm\"czex"
|
||||||
|
"h\"iiockj\\\xc1et"
|
||||||
|
"d\"rmjjftm"
|
||||||
|
"qlvhdcbqtyrhlc\\"
|
||||||
|
"yy\"rsucjtulm\"coryri\"eqjlbmk"
|
||||||
|
"tv"
|
||||||
|
"r\"bfuht\\jjgujp\""
|
||||||
|
"kukxvuauamtdosngdjlkauylttaokaj"
|
||||||
|
"srgost\"\"rbkcqtlccu\x65ohjptstrjkzy"
|
||||||
|
"yxwxl\\yjilwwxffrjjuazmzjs"
|
||||||
|
"dxlw\\fkstu\"hjrtiafhyuoh\"sewabne"
|
||||||
|
"\x88sj\"v"
|
||||||
|
"rfzprz\xec\"oxqclu\"krzefp\\q"
|
||||||
|
"cfmhdbjuhrcymgxpylllyvpni"
|
||||||
|
"ucrmjvmimmcq\x88\xd9\"lz"
|
||||||
|
"lujtt\""
|
||||||
|
"gvbqoixn\"pmledpjmo\"flydnwkfxllf"
|
||||||
|
"dvxqlbshhmelsk\x8big\"l"
|
||||||
|
"mx\x54lma\x8bbguxejg"
|
||||||
|
"\x66jdati\xeceieo"
|
||||||
|
"\"iyyupixei\x54ff"
|
||||||
|
"xohzf\"rbxsoksxamiu"
|
||||||
|
"vlhthspeshzbppa\x4drhqnohjop\"\"mfjd"
|
||||||
|
"f\"tvxxla\"vurian\"\"idjq\x3aptm\xc3olep"
|
||||||
|
"gzqz"
|
||||||
|
"kbq\\wogye\\altvi\\hbvmodny"
|
||||||
|
"j\xd8"
|
||||||
|
"ofjozdhkblvndl"
|
||||||
|
"hbitoupimbawimxlxqze"
|
||||||
|
"ypeleimnme"
|
||||||
|
"xfwdrzsc\\oxqamawyizvi\\y"
|
||||||
|
"enoikppx\xa1ixe\"yo\"gumye"
|
||||||
|
"fb"
|
||||||
|
"vzf"
|
||||||
|
"zxidr"
|
||||||
|
"cu\x31beirsywtskq"
|
||||||
|
"lxpjbvqzztafwezd"
|
||||||
|
"\\jyxeuo\x18bv"
|
||||||
|
"b\"vawc\"p\\\\giern\"b"
|
||||||
|
"odizunx\"\"t\\yicdn\"x\"sdiz"
|
||||||
|
"\"\"tebrtsi"
|
||||||
|
"ctyzsxv\xa6pegfkwsi\"tgyltaakytccb"
|
||||||
|
"htxwbofchvmzbppycccliyik\xe5a"
|
||||||
|
"ggsslefamsklezqkrd"
|
||||||
|
"rcep\"fnimwvvdx\"l"
|
||||||
|
"zyrzlqmd\x12egvqs\\llqyie"
|
||||||
|
"\x07gsqyrr\\rcyhyspsvn"
|
||||||
|
"butg\""
|
||||||
|
"gb"
|
||||||
|
"gywkoxf\"jsg\\wtopxvumirqxlwz"
|
||||||
|
"rj\"ir\"wldwveair\x2es\"dhjrdehbqnzl"
|
||||||
|
"ru\"elktnsbxufk\\ejufjfjlevt\\lrzd"
|
||||||
|
"\"widsvok"
|
||||||
|
"oy\"\x81nuesvw"
|
||||||
|
"ay"
|
||||||
|
"syticfac\x1cfjsivwlmy\"pumsqlqqzx"
|
||||||
|
"m"
|
||||||
|
"rjjkfh\x78cf\x2brgceg\"jmdyas\"\\xlv\xb6p"
|
||||||
|
"tmuvo\"\x3ffdqdovjmdmkgpstotojkv\"as"
|
||||||
|
"jd\\ojvynhxllfzzxvbn\"wrpphcvx"
|
||||||
|
"pz"
|
||||||
|
"\"twr"
|
||||||
|
"n\\hdzmxe\"mzjjeadlz"
|
||||||
|
"fb\"rprxuagvahjnri"
|
||||||
|
"rfmexmjjgh\\xrnmyvnatrvfruflaqjnd"
|
||||||
|
"obbbde\"co\"qr\"qpiwjgqahqm\\jjp\""
|
||||||
|
"vpbq\"\"y\"czk\\b\x52ed\"lnzepobp"
|
||||||
|
"syzeajzfarplydipny\"y\"\xe8ad"
|
||||||
|
"mpyodwb"
|
||||||
|
"\x47rakphlqqptd"
|
||||||
|
"wa\"oj\"aiy"
|
||||||
|
"a"
|
||||||
|
"ropozx"
|
||||||
|
"q\x51nbtlwa"
|
||||||
|
"etukvgx\\jqxlkq"
|
||||||
|
"\"tp\"rah\"pg\"s\"bpdtes\\tkasdhqd"
|
||||||
|
"dn\"qqpkikadowssb\xcah\"dzpsf\\ect\"jdh"
|
||||||
|
"pxunovbbrrn\\vullyn\"bno\"\"\"myfxlp\""
|
||||||
|
"qaixyazuryvkmoulhcqaotegfj\\mpzm"
|
||||||
|
"bvfrbicutzbjwn\\oml\"cf\"d\"ezcpv\"j"
|
||||||
|
"rmbrdtneudemigdhelmb"
|
||||||
|
"aq\\aurmbhy"
|
||||||
|
"wujqvzw"
|
||||||
|
"gf\"tssmvm\"gm\"hu\x9a\xb7yjawsa"
|
||||||
|
"hrhqqxow\xe2gsydtdspcfqy\"zw\\ou"
|
||||||
|
"ianwwf\\yko\\tdujhhqdi"
|
||||||
|
"xylz\"zpvpab"
|
||||||
|
"lwuopbeeegp"
|
||||||
|
"aoop\x49jhhcexdmdtun"
|
||||||
|
"\\\\mouqqcsgmz"
|
||||||
|
"tltuvwhveau\x43b\"ymxjlcgiymcynwt"
|
||||||
|
"gsugerumpyuhtjljbhrdyoj"
|
||||||
|
"lnjm\xb8wg\"ajh"
|
||||||
|
"zmspue\"nfttdon\\b\"eww"
|
||||||
|
"\"w\x67jwaq\x7ernmyvs\\rmdsuwydsd\"th"
|
||||||
|
"ogtgvtlmcvgllyv"
|
||||||
|
"z\"fqi\"rvddoehrciyl"
|
||||||
|
"yustxxtot\"muec\"xvfdbzunzvveq"
|
||||||
|
"mqslw"
|
||||||
|
"txqnyvzmibqgjs\xb6xy\x86nfalfyx"
|
||||||
|
"kzhehlmkholov"
|
||||||
|
"plpmywcnirrjutjguosh\\"
|
||||||
|
"pydbnqofv\"dn\\m"
|
||||||
|
"aegqof"
|
||||||
|
"eambmxt\\dxagoogl\\zapfwwlmk"
|
||||||
|
"afbmqitxxqhddlozuxcpjxgh"
|
||||||
|
"vgts"
|
||||||
|
"bfdpqtoxzzhmzcilehnflna"
|
||||||
|
"s\"idpz"
|
||||||
|
"\xcfhgly\"nlmztwybx\"ecezmsxaqw"
|
||||||
|
"aackfgndqcqiy"
|
||||||
|
"\x22unqdlsrvgzfaohoffgxzfpir\"s"
|
||||||
|
"abh\"ydv\"kbpdhrerl"
|
||||||
|
"bdzpg"
|
||||||
|
"ekwgkywtmzp"
|
||||||
|
"wtoodejqmrrgslhvnk\"pi\"ldnogpth"
|
||||||
|
"njro\x68qgbx\xe4af\"\\suan"
|
49
2015/day08/main.go
Normal file
49
2015/day08/main.go
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"io"
|
||||||
|
"log"
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
var input []string
|
||||||
|
var readInp string
|
||||||
|
for {
|
||||||
|
_, err := fmt.Scan(&readInp)
|
||||||
|
if err != nil {
|
||||||
|
if err != io.EOF {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
break
|
||||||
|
}
|
||||||
|
input = append(input, readInp)
|
||||||
|
}
|
||||||
|
|
||||||
|
var codeCount int
|
||||||
|
var stringCount int
|
||||||
|
for i := range input {
|
||||||
|
codeCount += len(input[i])
|
||||||
|
var skipChars int
|
||||||
|
fmt.Printf("%s -> %d\n", input[i], len(input[i]))
|
||||||
|
tmpInput := strings.Replace(input[i], "\\\"", "\"", -1)
|
||||||
|
fmt.Printf("%s -> %d\n", tmpInput, len(tmpInput))
|
||||||
|
tmpInput = strings.Replace(tmpInput, "\\\\", "\\", -1)
|
||||||
|
fmt.Printf("%s -> %d\n", tmpInput, len(tmpInput))
|
||||||
|
tmpInput = strings.TrimSuffix(strings.TrimPrefix(tmpInput, "\""), "\"")
|
||||||
|
fmt.Printf("%s -> %d\n", tmpInput, len(tmpInput))
|
||||||
|
// Now search for hex sequences
|
||||||
|
for j := range tmpInput {
|
||||||
|
if len(tmpInput) > j+3 {
|
||||||
|
if tmpInput[j] == '\\' && tmpInput[j+1] == 'x' {
|
||||||
|
skipChars += 3
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
fmt.Printf("Minus %d for hex\n", skipChars)
|
||||||
|
stringCount += len(tmpInput) - skipChars
|
||||||
|
}
|
||||||
|
fmt.Printf("Code: %d, String: %d\n", codeCount, stringCount)
|
||||||
|
fmt.Printf("Difference: %d\n", (codeCount - stringCount))
|
||||||
|
}
|
95
2015/day08/problem
Normal file
95
2015/day08/problem
Normal file
@ -0,0 +1,95 @@
|
|||||||
|
Advent of Code
|
||||||
|
|
||||||
|
br0xen 40*
|
||||||
|
|
||||||
|
• [About]
|
||||||
|
• [Stats]
|
||||||
|
• [Leaderboard]
|
||||||
|
• [Settings]
|
||||||
|
• [Log out]
|
||||||
|
|
||||||
|
--- Day 8: Matchsticks ---
|
||||||
|
|
||||||
|
Space on the sleigh is limited this year, and so Santa will be bringing his list as a digital
|
||||||
|
copy. He needs to know how much space it will take up when stored.
|
||||||
|
|
||||||
|
It is common in many programming languages to provide a way to escape special characters in
|
||||||
|
strings. For example, C, JavaScript, Perl, Python, and even PHP handle special characters in
|
||||||
|
very similar ways.
|
||||||
|
|
||||||
|
However, it is important to realize the difference between the number of characters in the code
|
||||||
|
representation of the string literal and the number of characters in the in-memory string
|
||||||
|
itself.
|
||||||
|
|
||||||
|
For example:
|
||||||
|
|
||||||
|
• "" is 2 characters of code (the two double quotes), but the string contains zero
|
||||||
|
characters.
|
||||||
|
• "abc" is 5 characters of code, but 3 characters in the string data.
|
||||||
|
• "aaa\"aaa" is 10 characters of code, but the string itself contains six "a" characters and
|
||||||
|
a single, escaped quote character, for a total of 7 characters in the string data.
|
||||||
|
• "\x27" is 6 characters of code, but the string itself contains just one - an apostrophe
|
||||||
|
('), escaped using hexadecimal notation.
|
||||||
|
|
||||||
|
Santa's list is a file that contains many double-quoted string literals, one on each line. The
|
||||||
|
only escape sequences used are \\ (which represents a single backslash), \" (which represents a
|
||||||
|
lone double-quote character), and \x plus two hexadecimal characters (which represents a single
|
||||||
|
character with that ASCII code).
|
||||||
|
|
||||||
|
Disregarding the whitespace in the file, what is the number of characters of code for string
|
||||||
|
literals minus the number of characters in memory for the values of the strings in total for
|
||||||
|
the entire file?
|
||||||
|
|
||||||
|
For example, given the four strings above, the total number of characters of string code (2 + 5
|
||||||
|
+ 10 + 6 = 23) minus the total number of characters in memory for string values (0 + 3 + 7 + 1
|
||||||
|
= 11) is 23 - 11 = 12.
|
||||||
|
|
||||||
|
Your puzzle answer was 1350.
|
||||||
|
|
||||||
|
--- Part Two ---
|
||||||
|
|
||||||
|
Now, let's go the other way. In addition to finding the number of characters of code, you
|
||||||
|
should now encode each code representation as a new string and find the number of characters of
|
||||||
|
the new encoded representation, including the surrounding double quotes.
|
||||||
|
|
||||||
|
For example:
|
||||||
|
|
||||||
|
• "" encodes to "\"\"", an increase from 2 characters to 6.
|
||||||
|
• "abc" encodes to "\"abc\"", an increase from 5 characters to 9.
|
||||||
|
• "aaa\"aaa" encodes to "\"aaa\\\"aaa\"", an increase from 10 characters to 16.
|
||||||
|
• "\x27" encodes to "\"\\x27\"", an increase from 6 characters to 11.
|
||||||
|
|
||||||
|
Your task is to find the total number of characters to represent the newly encoded strings
|
||||||
|
minus the number of characters of code in each original string literal. For example, for the
|
||||||
|
strings above, the total encoded length (6 + 9 + 16 + 11 = 42) minus the characters in the
|
||||||
|
original code representation (23, just like in the first part of this puzzle) is 42 - 23 = 19.
|
||||||
|
|
||||||
|
Your puzzle answer was 2085.
|
||||||
|
|
||||||
|
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
|
||||||
|
. https://en.wikipedia.org/wiki/Escape_sequences_in_C
|
||||||
|
. https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String
|
||||||
|
. http://perldoc.perl.org/perlop.html#Quote-and-Quote-like-Operators
|
||||||
|
. https://docs.python.org/2.0/ref/strings.html
|
||||||
|
. http://php.net/manual/en/language.types.string.php#language.types.string.syntax.double
|
||||||
|
. http://adventofcode.com/
|
||||||
|
. http://adventofcode.com/day/8/input
|
||||||
|
. https://twitter.com/intent/tweet?text=I%27ve+completed+%22Matchsticks%22+%2D+Day+8+%2D+Advent+of+Code&url=http%3A%2F%2Fadventofcode%2Ecom%2Fday%2F8&related=ericwastl&hashtags=AdventOfCode
|
||||||
|
. https://plus.google.com/share?url=http%3A%2F%2Fadventofcode%2Ecom%2Fday%2F8
|
||||||
|
. http://www.reddit.com/submit?url=http%3A%2F%2Fadventofcode%2Ecom%2Fday%2F8&title=I%27ve+completed+%22Matchsticks%22+%2D+Day+8+%2D+Advent+of+Code
|
BIN
2015/day09/day9
Normal file
BIN
2015/day09/day9
Normal file
Binary file not shown.
28
2015/day09/input
Normal file
28
2015/day09/input
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
Tristram to AlphaCentauri = 34
|
||||||
|
Tristram to Snowdin = 100
|
||||||
|
Tristram to Tambi = 63
|
||||||
|
Tristram to Faerun = 108
|
||||||
|
Tristram to Norrath = 111
|
||||||
|
Tristram to Straylight = 89
|
||||||
|
Tristram to Arbre = 132
|
||||||
|
AlphaCentauri to Snowdin = 4
|
||||||
|
AlphaCentauri to Tambi = 79
|
||||||
|
AlphaCentauri to Faerun = 44
|
||||||
|
AlphaCentauri to Norrath = 147
|
||||||
|
AlphaCentauri to Straylight = 133
|
||||||
|
AlphaCentauri to Arbre = 74
|
||||||
|
Snowdin to Tambi = 105
|
||||||
|
Snowdin to Faerun = 95
|
||||||
|
Snowdin to Norrath = 48
|
||||||
|
Snowdin to Straylight = 88
|
||||||
|
Snowdin to Arbre = 7
|
||||||
|
Tambi to Faerun = 68
|
||||||
|
Tambi to Norrath = 134
|
||||||
|
Tambi to Straylight = 107
|
||||||
|
Tambi to Arbre = 40
|
||||||
|
Faerun to Norrath = 11
|
||||||
|
Faerun to Straylight = 66
|
||||||
|
Faerun to Arbre = 144
|
||||||
|
Norrath to Straylight = 115
|
||||||
|
Norrath to Arbre = 135
|
||||||
|
Straylight to Arbre = 127
|
166
2015/day09/main.go
Normal file
166
2015/day09/main.go
Normal file
@ -0,0 +1,166 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"io"
|
||||||
|
"log"
|
||||||
|
"os"
|
||||||
|
"strconv"
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
|
var allTowns map[string]roads
|
||||||
|
|
||||||
|
type roads map[string]int
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
allTowns = make(map[string]roads)
|
||||||
|
var input []string
|
||||||
|
var readInp, bldInput string
|
||||||
|
for {
|
||||||
|
_, err := fmt.Scan(&readInp)
|
||||||
|
if err != nil {
|
||||||
|
if err != io.EOF {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
break
|
||||||
|
}
|
||||||
|
|
||||||
|
if strings.HasSuffix(bldInput, "=") {
|
||||||
|
bldInput = bldInput + " " + readInp
|
||||||
|
input = append(input, bldInput)
|
||||||
|
bldInput = ""
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if len(bldInput) > 0 {
|
||||||
|
bldInput += " "
|
||||||
|
}
|
||||||
|
bldInput = bldInput + readInp
|
||||||
|
}
|
||||||
|
|
||||||
|
for i := range input {
|
||||||
|
dirTowns := strings.Split(input[i], " to ")
|
||||||
|
secondPart := strings.Split(dirTowns[1], " = ")
|
||||||
|
town1 := dirTowns[0]
|
||||||
|
town2 := secondPart[0]
|
||||||
|
distance := mustAtoi(secondPart[1])
|
||||||
|
buildRoute(town1, town2, distance)
|
||||||
|
}
|
||||||
|
|
||||||
|
// All routes should be built, find the shortest
|
||||||
|
var shortestRoute []string
|
||||||
|
shortestDistance := -1
|
||||||
|
for i := range allTowns {
|
||||||
|
var visited []string
|
||||||
|
lastVisit := i
|
||||||
|
tripDistance := 0
|
||||||
|
for len(visited) < len(allTowns) {
|
||||||
|
var dist int
|
||||||
|
visited = append(visited, lastVisit)
|
||||||
|
lastVisit, dist = findShortest(lastVisit, visited)
|
||||||
|
if dist > 0 {
|
||||||
|
tripDistance += dist
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if shortestDistance == -1 || tripDistance < shortestDistance {
|
||||||
|
shortestDistance = tripDistance
|
||||||
|
shortestRoute = visited
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Now find the longest
|
||||||
|
var longestRoute []string
|
||||||
|
longestDistance := -1
|
||||||
|
for i := range allTowns {
|
||||||
|
var visited []string
|
||||||
|
lastVisit := i
|
||||||
|
tripDistance := 0
|
||||||
|
for len(visited) < len(allTowns) {
|
||||||
|
var dist int
|
||||||
|
visited = append(visited, lastVisit)
|
||||||
|
lastVisit, dist = findLongest(lastVisit, visited)
|
||||||
|
if dist > 0 {
|
||||||
|
tripDistance += dist
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if longestDistance == -1 || tripDistance > longestDistance {
|
||||||
|
longestDistance = tripDistance
|
||||||
|
longestRoute = visited
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fmt.Println("Shortest Route:" + strconv.Itoa(shortestDistance))
|
||||||
|
fmt.Println(strings.Join(shortestRoute, "->"))
|
||||||
|
fmt.Println("Longest Route:" + strconv.Itoa(longestDistance))
|
||||||
|
fmt.Println(strings.Join(longestRoute, "->"))
|
||||||
|
}
|
||||||
|
|
||||||
|
func findShortest(from string, exclude []string) (string, int) {
|
||||||
|
var toTown string
|
||||||
|
shortest := -1
|
||||||
|
for j := range allTowns[from] {
|
||||||
|
var didIt bool
|
||||||
|
for ex := range exclude {
|
||||||
|
if j == exclude[ex] {
|
||||||
|
didIt = true
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if didIt {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
// Find the quickest trip from here
|
||||||
|
if shortest == -1 || allTowns[from][j] < shortest {
|
||||||
|
shortest = allTowns[from][j]
|
||||||
|
toTown = j
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return toTown, shortest
|
||||||
|
}
|
||||||
|
|
||||||
|
func findLongest(from string, exclude []string) (string, int) {
|
||||||
|
var toTown string
|
||||||
|
longest := -1
|
||||||
|
for j := range allTowns[from] {
|
||||||
|
var didIt bool
|
||||||
|
for ex := range exclude {
|
||||||
|
if j == exclude[ex] {
|
||||||
|
didIt = true
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if didIt {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
// Find the longest trip from here
|
||||||
|
if longest == -1 || allTowns[from][j] > longest {
|
||||||
|
longest = allTowns[from][j]
|
||||||
|
toTown = j
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return toTown, longest
|
||||||
|
}
|
||||||
|
|
||||||
|
func mustAtoi(i string) int {
|
||||||
|
var ret int
|
||||||
|
var err error
|
||||||
|
if ret, err = strconv.Atoi(i); err != nil {
|
||||||
|
fmt.Println("Tried to mustAtoi: " + i)
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
return ret
|
||||||
|
}
|
||||||
|
|
||||||
|
func buildRoute(t1, t2 string, dist int) {
|
||||||
|
if _, ok := allTowns[t1]; !ok {
|
||||||
|
// Add this town
|
||||||
|
allTowns[t1] = make(map[string]int)
|
||||||
|
}
|
||||||
|
allTowns[t1][t2] = dist
|
||||||
|
// And the other direction
|
||||||
|
if _, ok := allTowns[t2]; !ok {
|
||||||
|
// Add this town
|
||||||
|
allTowns[t2] = make(map[string]int)
|
||||||
|
}
|
||||||
|
allTowns[t2][t1] = dist
|
||||||
|
}
|
78
2015/day09/problem
Normal file
78
2015/day09/problem
Normal file
@ -0,0 +1,78 @@
|
|||||||
|
Advent of Code
|
||||||
|
|
||||||
|
br0xen 40*
|
||||||
|
|
||||||
|
• [About]
|
||||||
|
• [Stats]
|
||||||
|
• [Leaderboard]
|
||||||
|
• [Settings]
|
||||||
|
• [Log out]
|
||||||
|
|
||||||
|
--- Day 9: All in a Single Night ---
|
||||||
|
|
||||||
|
Every year, Santa manages to deliver all of his presents in a single night.
|
||||||
|
|
||||||
|
This year, however, he has some new locations to visit; his elves have provided him the
|
||||||
|
distances between every pair of locations. He can start and end at any two (different)
|
||||||
|
locations he wants, but he must visit each location exactly once. What is the shortest distance
|
||||||
|
he can travel to achieve this?
|
||||||
|
|
||||||
|
For example, given the following distances:
|
||||||
|
|
||||||
|
London to Dublin = 464
|
||||||
|
London to Belfast = 518
|
||||||
|
Dublin to Belfast = 141
|
||||||
|
|
||||||
|
The possible routes are therefore:
|
||||||
|
|
||||||
|
Dublin -> London -> Belfast = 982
|
||||||
|
London -> Dublin -> Belfast = 605
|
||||||
|
London -> Belfast -> Dublin = 659
|
||||||
|
Dublin -> Belfast -> London = 659
|
||||||
|
Belfast -> Dublin -> London = 605
|
||||||
|
Belfast -> London -> Dublin = 982
|
||||||
|
|
||||||
|
The shortest of these is London -> Dublin -> Belfast = 605, and so the answer is 605 in this
|
||||||
|
example.
|
||||||
|
|
||||||
|
What is the distance of the shortest route?
|
||||||
|
|
||||||
|
Your puzzle answer was 251.
|
||||||
|
|
||||||
|
--- Part Two ---
|
||||||
|
|
||||||
|
The next year, just to show off, Santa decides to take the route with the longest distance
|
||||||
|
instead.
|
||||||
|
|
||||||
|
He can still start and end at any two (different) locations he wants, and he still must visit
|
||||||
|
each location exactly once.
|
||||||
|
|
||||||
|
For example, given the distances above, the longest route would be 982 via (for example) Dublin
|
||||||
|
-> London -> Belfast.
|
||||||
|
|
||||||
|
What is the distance of the longest route?
|
||||||
|
|
||||||
|
Your puzzle answer was 898.
|
||||||
|
|
||||||
|
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/9/input
|
||||||
|
. https://twitter.com/intent/tweet?text=I%27ve+completed+%22All+in+a+Single+Night%22+%2D+Day+9+%2D+Advent+of+Code&url=http%3A%2F%2Fadventofcode%2Ecom%2Fday%2F9&related=ericwastl&hashtags=AdventOfCode
|
||||||
|
. https://plus.google.com/share?url=http%3A%2F%2Fadventofcode%2Ecom%2Fday%2F9
|
||||||
|
. http://www.reddit.com/submit?url=http%3A%2F%2Fadventofcode%2Ecom%2Fday%2F9&title=I%27ve+completed+%22All+in+a+Single+Night%22+%2D+Day+9+%2D+Advent+of+Code
|
1
2015/day10/input
Normal file
1
2015/day10/input
Normal file
@ -0,0 +1 @@
|
|||||||
|
1113122113
|
76
2015/day10/main.go
Normal file
76
2015/day10/main.go
Normal file
@ -0,0 +1,76 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
"strconv"
|
||||||
|
)
|
||||||
|
|
||||||
|
func printUsage() {
|
||||||
|
fmt.Println("Usage: day10 <look-and-say> [iterations]")
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Pt 2 Result:
|
||||||
|
Length of result: 5103798
|
||||||
|
*/
|
||||||
|
func main() {
|
||||||
|
var debugMode bool
|
||||||
|
|
||||||
|
args := os.Args
|
||||||
|
if len(args) < 2 {
|
||||||
|
printUsage()
|
||||||
|
}
|
||||||
|
var lasString string
|
||||||
|
lasString = args[1]
|
||||||
|
|
||||||
|
var iter int
|
||||||
|
var err error
|
||||||
|
if len(args) > 2 {
|
||||||
|
if iter, err = strconv.Atoi(args[2]); err != nil {
|
||||||
|
printUsage()
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
iter = 40
|
||||||
|
}
|
||||||
|
if len(args) > 3 {
|
||||||
|
if args[2] == "--debug" {
|
||||||
|
debugMode = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fmt.Printf("Iterate %d times over %s\n", iter, lasString)
|
||||||
|
for i := 0; i < iter; i++ {
|
||||||
|
fmt.Print("O")
|
||||||
|
if i%10 == 9 {
|
||||||
|
fmt.Println(" " + strconv.Itoa(len(lasString)))
|
||||||
|
}
|
||||||
|
r := lookAndSay(lasString)
|
||||||
|
if debugMode {
|
||||||
|
fmt.Println(strconv.Itoa(i) + " >> " + r)
|
||||||
|
}
|
||||||
|
lasString = r
|
||||||
|
}
|
||||||
|
fmt.Println("\nLength of result: " + strconv.Itoa(len(lasString)))
|
||||||
|
}
|
||||||
|
|
||||||
|
func lookAndSay(str string) string {
|
||||||
|
numI := 1
|
||||||
|
var ret string
|
||||||
|
|
||||||
|
strLen := len(str)
|
||||||
|
|
||||||
|
for i := range str {
|
||||||
|
if strLen > i+1 {
|
||||||
|
if str[i+1] != str[i] {
|
||||||
|
ret += strconv.Itoa(numI) + string(str[i])
|
||||||
|
numI = 0
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// Last char in string
|
||||||
|
ret += strconv.Itoa(numI) + string(str[i])
|
||||||
|
}
|
||||||
|
numI++
|
||||||
|
}
|
||||||
|
return ret
|
||||||
|
}
|
66
2015/day10/problem
Normal file
66
2015/day10/problem
Normal file
@ -0,0 +1,66 @@
|
|||||||
|
Advent of Code
|
||||||
|
|
||||||
|
br0xen 40*
|
||||||
|
|
||||||
|
• [About]
|
||||||
|
• [Stats]
|
||||||
|
• [Leaderboard]
|
||||||
|
• [Settings]
|
||||||
|
• [Log out]
|
||||||
|
|
||||||
|
--- Day 10: Elves Look, Elves Say ---
|
||||||
|
|
||||||
|
Today, the Elves are playing a game called look-and-say. They take turns making sequences by
|
||||||
|
reading aloud the previous sequence and using that reading as the next sequence. For example,
|
||||||
|
211 is read as "one two, two ones", which becomes 1221 (1 2, 2 1s).
|
||||||
|
|
||||||
|
Look-and-say sequences are generated iteratively, using the previous value as input for the
|
||||||
|
next step. For each step, take the previous value, and replace each run of digits (like 111)
|
||||||
|
with the number of digits (3) followed by the digit itself (1).
|
||||||
|
|
||||||
|
For example:
|
||||||
|
|
||||||
|
• 1 becomes 11 (1 copy of digit 1).
|
||||||
|
• 11 becomes 21 (2 copies of digit 1).
|
||||||
|
• 21 becomes 1211 (one 2 followed by one 1).
|
||||||
|
• 1211 becomes 111221 (one 1, one 2, and two 1s).
|
||||||
|
• 111221 becomes 312211 (three 1s, two 2s, and one 1).
|
||||||
|
|
||||||
|
Starting with the digits in your puzzle input, apply this process 40 times. What is the length
|
||||||
|
of the result?
|
||||||
|
|
||||||
|
Your puzzle answer was 360154.
|
||||||
|
|
||||||
|
--- Part Two ---
|
||||||
|
|
||||||
|
Neat, right? You might also enjoy hearing John Conway talking about this sequence (that's
|
||||||
|
Conway of Conway's Game of Life fame).
|
||||||
|
|
||||||
|
Now, starting again with the digits in your puzzle input, apply this process 50 times. What is
|
||||||
|
the length of the new result?
|
||||||
|
|
||||||
|
Your puzzle answer was 5103798.
|
||||||
|
|
||||||
|
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 1113122113.
|
||||||
|
|
||||||
|
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
|
||||||
|
. https://en.wikipedia.org/wiki/Look-and-say_sequence
|
||||||
|
. https://www.youtube.com/watch?v=ea7lJkEhytA
|
||||||
|
. http://adventofcode.com/
|
||||||
|
. https://twitter.com/intent/tweet?text=I%27ve+completed+%22Elves+Look%2C+Elves+Say%22+%2D+Day+10+%2D+Advent+of+Code&url=http%3A%2F%2Fadventofcode%2Ecom%2Fday%2F10&related=ericwastl&hashtags=AdventOfCode
|
||||||
|
. https://plus.google.com/share?url=http%3A%2F%2Fadventofcode%2Ecom%2Fday%2F10
|
||||||
|
. http://www.reddit.com/submit?url=http%3A%2F%2Fadventofcode%2Ecom%2Fday%2F10&title=I%27ve+completed+%22Elves+Look%2C+Elves+Say%22+%2D+Day+10+%2D+Advent+of+Code
|
1
2015/day11/input
Normal file
1
2015/day11/input
Normal file
@ -0,0 +1 @@
|
|||||||
|
hepxcrrq
|
95
2015/day11/main.go
Normal file
95
2015/day11/main.go
Normal file
@ -0,0 +1,95 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
|
func printUsage() {
|
||||||
|
fmt.Println("Usage: day11 <string> [add-amt]")
|
||||||
|
fmt.Println("If add-amt isn't given, we just add 1")
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
args := os.Args
|
||||||
|
if len(args) < 2 {
|
||||||
|
printUsage()
|
||||||
|
}
|
||||||
|
var orig string
|
||||||
|
orig = args[1]
|
||||||
|
|
||||||
|
var valid bool
|
||||||
|
for !valid {
|
||||||
|
orig = addOneToString(orig)
|
||||||
|
valid = testPassword(orig)
|
||||||
|
}
|
||||||
|
fmt.Println(orig)
|
||||||
|
}
|
||||||
|
|
||||||
|
func addOneToString(s string) string {
|
||||||
|
lastPlace := s[len(s)-1]
|
||||||
|
ret := s[:len(s)-1]
|
||||||
|
if lastPlace == 'z' {
|
||||||
|
lastPlace = 'a'
|
||||||
|
ret = addOneToString(s[:len(s)-1])
|
||||||
|
} else {
|
||||||
|
lastPlace++
|
||||||
|
}
|
||||||
|
return ret + string(lastPlace)
|
||||||
|
}
|
||||||
|
|
||||||
|
func testPassword(s string) bool {
|
||||||
|
if hasValidChars(s) && hasStraight(s) && hasDoubles(s) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
// Test if string contains only valid chars
|
||||||
|
func hasValidChars(s string) bool {
|
||||||
|
if strings.Count(s, "i") > 0 {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
if strings.Count(s, "o") > 0 {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
if strings.Count(s, "l") > 0 {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
// Test if string has a 3 char straight
|
||||||
|
func hasStraight(s string) bool {
|
||||||
|
for i := range s {
|
||||||
|
if i > 1 {
|
||||||
|
if (s[i-2] == s[i]-2) && (s[i-1] == s[i]-1) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
// Test if string has 2 doubles
|
||||||
|
func hasDoubles(s string) bool {
|
||||||
|
if i := hasDouble(s); i >= 0 {
|
||||||
|
return (hasDouble(s[i+2:]) >= 0)
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
// Returns index of first double in string
|
||||||
|
// -1 if there isn't one
|
||||||
|
func hasDouble(s string) int {
|
||||||
|
for i := range s {
|
||||||
|
if i > 0 {
|
||||||
|
if s[i-1] == s[i] {
|
||||||
|
return i - 1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return -1
|
||||||
|
}
|
75
2015/day11/problem
Normal file
75
2015/day11/problem
Normal file
@ -0,0 +1,75 @@
|
|||||||
|
Advent of Code
|
||||||
|
|
||||||
|
br0xen 40*
|
||||||
|
|
||||||
|
• [About]
|
||||||
|
• [Stats]
|
||||||
|
• [Leaderboard]
|
||||||
|
• [Settings]
|
||||||
|
• [Log out]
|
||||||
|
|
||||||
|
--- Day 11: Corporate Policy ---
|
||||||
|
|
||||||
|
Santa's previous password expired, and he needs help choosing a new one.
|
||||||
|
|
||||||
|
To help him remember his new password after the old one expires, Santa has devised a method of
|
||||||
|
coming up with a password based on the previous one. Corporate policy dictates that passwords
|
||||||
|
must be exactly eight lowercase letters (for security reasons), so he finds his new password by
|
||||||
|
incrementing his old password string repeatedly until it is valid.
|
||||||
|
|
||||||
|
Incrementing is just like counting with numbers: xx, xy, xz, ya, yb, and so on. Increase the
|
||||||
|
rightmost letter one step; if it was z, it wraps around to a, and repeat with the next letter
|
||||||
|
to the left until one doesn't wrap around.
|
||||||
|
|
||||||
|
Unfortunately for Santa, a new Security-Elf recently started, and he has imposed some
|
||||||
|
additional password requirements:
|
||||||
|
|
||||||
|
• Passwords must include one increasing straight of at least three letters, like abc, bcd,
|
||||||
|
cde, and so on, up to xyz. They cannot skip letters; abd doesn't count.
|
||||||
|
• Passwords may not contain the letters i, o, or l, as these letters can be mistaken for
|
||||||
|
other characters and are therefore confusing.
|
||||||
|
• Passwords must contain at least two different, non-overlapping pairs of letters, like aa,
|
||||||
|
bb, or zz.
|
||||||
|
|
||||||
|
For example:
|
||||||
|
|
||||||
|
• hijklmmn meets the first requirement (because it contains the straight hij) but fails the
|
||||||
|
second requirement requirement (because it contains i and l).
|
||||||
|
• abbceffg meets the third requirement (because it repeats bb and ff) but fails the first
|
||||||
|
requirement.
|
||||||
|
• abbcegjk fails the third requirement, because it only has one double letter (bb).
|
||||||
|
• The next password after abcdefgh is abcdffaa.
|
||||||
|
• The next password after ghijklmn is ghjaabcc, because you eventually skip all the passwords
|
||||||
|
that start with ghi..., since i is not allowed.
|
||||||
|
|
||||||
|
Given Santa's current password (your puzzle input), what should his next password be?
|
||||||
|
|
||||||
|
Your puzzle answer was hepxxyzz.
|
||||||
|
|
||||||
|
--- Part Two ---
|
||||||
|
|
||||||
|
Santa's password expired again. What's the next one?
|
||||||
|
|
||||||
|
Your puzzle answer was heqaabcc.
|
||||||
|
|
||||||
|
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 hepxcrrq.
|
||||||
|
|
||||||
|
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+%22Corporate+Policy%22+%2D+Day+11+%2D+Advent+of+Code&url=http%3A%2F%2Fadventofcode%2Ecom%2Fday%2F11&related=ericwastl&hashtags=AdventOfCode
|
||||||
|
. https://plus.google.com/share?url=http%3A%2F%2Fadventofcode%2Ecom%2Fday%2F11
|
||||||
|
. http://www.reddit.com/submit?url=http%3A%2F%2Fadventofcode%2Ecom%2Fday%2F11&title=I%27ve+completed+%22Corporate+Policy%22+%2D+Day+11+%2D+Advent+of+Code
|
1
2015/day12/input
Normal file
1
2015/day12/input
Normal file
File diff suppressed because one or more lines are too long
133
2015/day12/main.go
Normal file
133
2015/day12/main.go
Normal file
@ -0,0 +1,133 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"io"
|
||||||
|
"log"
|
||||||
|
"os"
|
||||||
|
"regexp"
|
||||||
|
"strconv"
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
var inpArr []string
|
||||||
|
var input, readInp string
|
||||||
|
for {
|
||||||
|
_, err := fmt.Scan(&readInp)
|
||||||
|
if err != nil {
|
||||||
|
if err != io.EOF {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
break
|
||||||
|
}
|
||||||
|
inpArr = append(inpArr, readInp)
|
||||||
|
}
|
||||||
|
input = strings.Join(inpArr, "")
|
||||||
|
|
||||||
|
//fmt.Println("Part 1 Solution: " + strconv.Itoa(sumAllInts(input)))
|
||||||
|
fmt.Println("Part 2 Solution: " + strconv.Itoa(sumAllInts(removeAllValue(input, "red"))))
|
||||||
|
//removeAllValue(input, "red")
|
||||||
|
}
|
||||||
|
|
||||||
|
func removeAllValue(s string, remove string) string {
|
||||||
|
ret := s
|
||||||
|
var removed bool
|
||||||
|
//ret, _ = removeFirstValue(ret, remove)
|
||||||
|
ret, removed = removeFirstValue(ret, remove)
|
||||||
|
for removed {
|
||||||
|
ret, removed = removeFirstValue(ret, remove)
|
||||||
|
}
|
||||||
|
return ret
|
||||||
|
}
|
||||||
|
|
||||||
|
// Not quite returning proper JSON... But may be good enough
|
||||||
|
// for the problem (since we're not looking for JSON output
|
||||||
|
// anyways
|
||||||
|
func removeFirstValue(s string, remove string) (string, bool) {
|
||||||
|
ret := s
|
||||||
|
var curlIdx []int
|
||||||
|
removeStart := -1
|
||||||
|
for i := range s {
|
||||||
|
if s[i] == '{' {
|
||||||
|
curlIdx = pushLevel(curlIdx, i)
|
||||||
|
}
|
||||||
|
if checkForValueAtIdx(s, ":\""+remove+"\"", i) {
|
||||||
|
removeStart, curlIdx = popLevel(curlIdx)
|
||||||
|
ret = strings.Replace(ret, trimAtClose(s[removeStart:]), "", -1)
|
||||||
|
// Now figure out if we have an abandoned key
|
||||||
|
if ret[removeStart-1] == ':' {
|
||||||
|
// Trackback in ret until we find the matching " and remove up to removeStart
|
||||||
|
remTrackBack := removeStart - 3
|
||||||
|
for ret[remTrackBack] != '"' {
|
||||||
|
remTrackBack--
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ret, true
|
||||||
|
}
|
||||||
|
if s[i] == '}' {
|
||||||
|
_, curlIdx = popLevel(curlIdx)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ret, false
|
||||||
|
}
|
||||||
|
|
||||||
|
// Trim string after closing bracket/brace
|
||||||
|
func trimAtClose(s string) string {
|
||||||
|
var levelStack []int
|
||||||
|
for i := range s {
|
||||||
|
if s[i] == '[' || s[i] == '{' {
|
||||||
|
levelStack = pushLevel(levelStack, i)
|
||||||
|
} else if s[i] == ']' || s[i] == '}' {
|
||||||
|
idx := -1
|
||||||
|
idx, levelStack = popLevel(levelStack)
|
||||||
|
if idx == 0 {
|
||||||
|
endIdx := i + 1
|
||||||
|
if s[i+1] == ',' {
|
||||||
|
endIdx++
|
||||||
|
}
|
||||||
|
return s[:endIdx]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return s
|
||||||
|
}
|
||||||
|
|
||||||
|
// Checks if the s contains v starting at index i
|
||||||
|
func checkForValueAtIdx(s string, v string, i int) bool {
|
||||||
|
if len(s) > i+len(v) {
|
||||||
|
if s[i:i+len(v)] == v {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
// Simple Part 1 solution
|
||||||
|
func sumAllInts(s string) int {
|
||||||
|
var allIntStrings []string
|
||||||
|
re := regexp.MustCompile("[-]?[0-9]+")
|
||||||
|
allIntStrings = append(allIntStrings, re.FindAllString(s, -1)...)
|
||||||
|
var sum int
|
||||||
|
for i := range allIntStrings {
|
||||||
|
sum += mustAtoi(allIntStrings[i])
|
||||||
|
}
|
||||||
|
return sum
|
||||||
|
}
|
||||||
|
|
||||||
|
func pushLevel(stack []int, n int) []int {
|
||||||
|
return append(stack, n)
|
||||||
|
}
|
||||||
|
|
||||||
|
func popLevel(stack []int) (int, []int) {
|
||||||
|
return stack[len(stack)-1], stack[:len(stack)-1]
|
||||||
|
}
|
||||||
|
|
||||||
|
func mustAtoi(s string) int {
|
||||||
|
r, err := strconv.Atoi(s)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println("Tried to Atoi " + s)
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
return r
|
||||||
|
}
|
70
2015/day12/problem
Normal file
70
2015/day12/problem
Normal file
@ -0,0 +1,70 @@
|
|||||||
|
Advent of Code
|
||||||
|
|
||||||
|
br0xen 40*
|
||||||
|
|
||||||
|
• [About]
|
||||||
|
• [Stats]
|
||||||
|
• [Leaderboard]
|
||||||
|
• [Settings]
|
||||||
|
• [Log out]
|
||||||
|
|
||||||
|
--- Day 12: JSAbacusFramework.io ---
|
||||||
|
|
||||||
|
Santa's Accounting-Elves need help balancing the books after a recent order. Unfortunately,
|
||||||
|
their accounting software uses a peculiar storage format. That's where you come in.
|
||||||
|
|
||||||
|
They have a JSON document which contains a variety of things: arrays ([1,2,3]), objects
|
||||||
|
({"a":1, "b":2}), numbers, and strings. Your first job is to simply find all of the numbers
|
||||||
|
throughout the document and add them together.
|
||||||
|
|
||||||
|
For example:
|
||||||
|
|
||||||
|
• [1,2,3] and {"a":2,"b":4} both have a sum of 6.
|
||||||
|
• [[[3]]] and {"a":{"b":4},"c":-1} both have a sum of 3.
|
||||||
|
• {"a":[-1,1]} and [-1,{"a":1}] both have a sum of 0.
|
||||||
|
• [] and {} both have a sum of 0.
|
||||||
|
|
||||||
|
You will not encounter any strings containing numbers.
|
||||||
|
|
||||||
|
What is the sum of all numbers in the document?
|
||||||
|
|
||||||
|
Your puzzle answer was 191164.
|
||||||
|
|
||||||
|
--- Part Two ---
|
||||||
|
|
||||||
|
Uh oh - the Accounting-Elves have realized that they double-counted everything red.
|
||||||
|
|
||||||
|
Ignore any object (and all of its children) which has any property with the value "red". Do
|
||||||
|
this only for objects ({...}), not arrays ([...]).
|
||||||
|
|
||||||
|
• [1,2,3] still has a sum of 6.
|
||||||
|
• [1,{"c":"red","b":2},3] now has a sum of 4, because the middle object is ignored.
|
||||||
|
• {"d":"red","e":[1,2,3,4],"f":5} now has a sum of 0, because the entire structure is
|
||||||
|
ignored.
|
||||||
|
• [1,"red",5] has a sum of 6, because "red" in an array has no effect.
|
||||||
|
|
||||||
|
Your puzzle answer was 87842.
|
||||||
|
|
||||||
|
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://json.org/
|
||||||
|
. http://adventofcode.com/
|
||||||
|
. http://adventofcode.com/day/12/input
|
||||||
|
. https://twitter.com/intent/tweet?text=I%27ve+completed+%22JSAbacusFramework%2Eio%22+%2D+Day+12+%2D+Advent+of+Code&url=http%3A%2F%2Fadventofcode%2Ecom%2Fday%2F12&related=ericwastl&hashtags=AdventOfCode
|
||||||
|
. https://plus.google.com/share?url=http%3A%2F%2Fadventofcode%2Ecom%2Fday%2F12
|
||||||
|
. http://www.reddit.com/submit?url=http%3A%2F%2Fadventofcode%2Ecom%2Fday%2F12&title=I%27ve+completed+%22JSAbacusFramework%2Eio%22+%2D+Day+12+%2D+Advent+of+Code
|
56
2015/day13/input
Normal file
56
2015/day13/input
Normal file
@ -0,0 +1,56 @@
|
|||||||
|
Alice would gain 2 happiness units by sitting next to Bob.
|
||||||
|
Alice would gain 26 happiness units by sitting next to Carol.
|
||||||
|
Alice would lose 82 happiness units by sitting next to David.
|
||||||
|
Alice would lose 75 happiness units by sitting next to Eric.
|
||||||
|
Alice would gain 42 happiness units by sitting next to Frank.
|
||||||
|
Alice would gain 38 happiness units by sitting next to George.
|
||||||
|
Alice would gain 39 happiness units by sitting next to Mallory.
|
||||||
|
Bob would gain 40 happiness units by sitting next to Alice.
|
||||||
|
Bob would lose 61 happiness units by sitting next to Carol.
|
||||||
|
Bob would lose 15 happiness units by sitting next to David.
|
||||||
|
Bob would gain 63 happiness units by sitting next to Eric.
|
||||||
|
Bob would gain 41 happiness units by sitting next to Frank.
|
||||||
|
Bob would gain 30 happiness units by sitting next to George.
|
||||||
|
Bob would gain 87 happiness units by sitting next to Mallory.
|
||||||
|
Carol would lose 35 happiness units by sitting next to Alice.
|
||||||
|
Carol would lose 99 happiness units by sitting next to Bob.
|
||||||
|
Carol would lose 51 happiness units by sitting next to David.
|
||||||
|
Carol would gain 95 happiness units by sitting next to Eric.
|
||||||
|
Carol would gain 90 happiness units by sitting next to Frank.
|
||||||
|
Carol would lose 16 happiness units by sitting next to George.
|
||||||
|
Carol would gain 94 happiness units by sitting next to Mallory.
|
||||||
|
David would gain 36 happiness units by sitting next to Alice.
|
||||||
|
David would lose 18 happiness units by sitting next to Bob.
|
||||||
|
David would lose 65 happiness units by sitting next to Carol.
|
||||||
|
David would lose 18 happiness units by sitting next to Eric.
|
||||||
|
David would lose 22 happiness units by sitting next to Frank.
|
||||||
|
David would gain 2 happiness units by sitting next to George.
|
||||||
|
David would gain 42 happiness units by sitting next to Mallory.
|
||||||
|
Eric would lose 65 happiness units by sitting next to Alice.
|
||||||
|
Eric would gain 24 happiness units by sitting next to Bob.
|
||||||
|
Eric would gain 100 happiness units by sitting next to Carol.
|
||||||
|
Eric would gain 51 happiness units by sitting next to David.
|
||||||
|
Eric would gain 21 happiness units by sitting next to Frank.
|
||||||
|
Eric would gain 55 happiness units by sitting next to George.
|
||||||
|
Eric would lose 44 happiness units by sitting next to Mallory.
|
||||||
|
Frank would lose 48 happiness units by sitting next to Alice.
|
||||||
|
Frank would gain 91 happiness units by sitting next to Bob.
|
||||||
|
Frank would gain 8 happiness units by sitting next to Carol.
|
||||||
|
Frank would lose 66 happiness units by sitting next to David.
|
||||||
|
Frank would gain 97 happiness units by sitting next to Eric.
|
||||||
|
Frank would lose 9 happiness units by sitting next to George.
|
||||||
|
Frank would lose 92 happiness units by sitting next to Mallory.
|
||||||
|
George would lose 44 happiness units by sitting next to Alice.
|
||||||
|
George would lose 25 happiness units by sitting next to Bob.
|
||||||
|
George would gain 17 happiness units by sitting next to Carol.
|
||||||
|
George would gain 92 happiness units by sitting next to David.
|
||||||
|
George would lose 92 happiness units by sitting next to Eric.
|
||||||
|
George would gain 18 happiness units by sitting next to Frank.
|
||||||
|
George would gain 97 happiness units by sitting next to Mallory.
|
||||||
|
Mallory would gain 92 happiness units by sitting next to Alice.
|
||||||
|
Mallory would lose 96 happiness units by sitting next to Bob.
|
||||||
|
Mallory would lose 51 happiness units by sitting next to Carol.
|
||||||
|
Mallory would lose 81 happiness units by sitting next to David.
|
||||||
|
Mallory would gain 31 happiness units by sitting next to Eric.
|
||||||
|
Mallory would lose 73 happiness units by sitting next to Frank.
|
||||||
|
Mallory would lose 89 happiness units by sitting next to George.
|
71
2015/day13/inputwithme
Normal file
71
2015/day13/inputwithme
Normal file
@ -0,0 +1,71 @@
|
|||||||
|
Alice would gain 2 happiness units by sitting next to Bob.
|
||||||
|
Alice would gain 26 happiness units by sitting next to Carol.
|
||||||
|
Alice would lose 82 happiness units by sitting next to David.
|
||||||
|
Alice would lose 75 happiness units by sitting next to Eric.
|
||||||
|
Alice would gain 42 happiness units by sitting next to Frank.
|
||||||
|
Alice would gain 38 happiness units by sitting next to George.
|
||||||
|
Alice would gain 39 happiness units by sitting next to Mallory.
|
||||||
|
Alice would gain 0 happiness units by sitting next to Brian.
|
||||||
|
Bob would gain 40 happiness units by sitting next to Alice.
|
||||||
|
Bob would lose 61 happiness units by sitting next to Carol.
|
||||||
|
Bob would lose 15 happiness units by sitting next to David.
|
||||||
|
Bob would gain 63 happiness units by sitting next to Eric.
|
||||||
|
Bob would gain 41 happiness units by sitting next to Frank.
|
||||||
|
Bob would gain 30 happiness units by sitting next to George.
|
||||||
|
Bob would gain 87 happiness units by sitting next to Mallory.
|
||||||
|
Bob would gain 0 happiness units by sitting next to Brian.
|
||||||
|
Carol would lose 35 happiness units by sitting next to Alice.
|
||||||
|
Carol would lose 99 happiness units by sitting next to Bob.
|
||||||
|
Carol would lose 51 happiness units by sitting next to David.
|
||||||
|
Carol would gain 95 happiness units by sitting next to Eric.
|
||||||
|
Carol would gain 90 happiness units by sitting next to Frank.
|
||||||
|
Carol would lose 16 happiness units by sitting next to George.
|
||||||
|
Carol would gain 94 happiness units by sitting next to Mallory.
|
||||||
|
Carol would gain 0 happiness units by sitting next to Brian.
|
||||||
|
David would gain 36 happiness units by sitting next to Alice.
|
||||||
|
David would lose 18 happiness units by sitting next to Bob.
|
||||||
|
David would lose 65 happiness units by sitting next to Carol.
|
||||||
|
David would lose 18 happiness units by sitting next to Eric.
|
||||||
|
David would lose 22 happiness units by sitting next to Frank.
|
||||||
|
David would gain 2 happiness units by sitting next to George.
|
||||||
|
David would gain 42 happiness units by sitting next to Mallory.
|
||||||
|
David would gain 0 happiness units by sitting next to Brian.
|
||||||
|
Eric would lose 65 happiness units by sitting next to Alice.
|
||||||
|
Eric would gain 24 happiness units by sitting next to Bob.
|
||||||
|
Eric would gain 100 happiness units by sitting next to Carol.
|
||||||
|
Eric would gain 51 happiness units by sitting next to David.
|
||||||
|
Eric would gain 21 happiness units by sitting next to Frank.
|
||||||
|
Eric would gain 55 happiness units by sitting next to George.
|
||||||
|
Eric would lose 44 happiness units by sitting next to Mallory.
|
||||||
|
Eric would gain 0 happiness units by sitting next to Brian.
|
||||||
|
Frank would lose 48 happiness units by sitting next to Alice.
|
||||||
|
Frank would gain 91 happiness units by sitting next to Bob.
|
||||||
|
Frank would gain 8 happiness units by sitting next to Carol.
|
||||||
|
Frank would lose 66 happiness units by sitting next to David.
|
||||||
|
Frank would gain 97 happiness units by sitting next to Eric.
|
||||||
|
Frank would lose 9 happiness units by sitting next to George.
|
||||||
|
Frank would lose 92 happiness units by sitting next to Mallory.
|
||||||
|
Frank would gain 0 happiness units by sitting next to Brian.
|
||||||
|
George would lose 44 happiness units by sitting next to Alice.
|
||||||
|
George would lose 25 happiness units by sitting next to Bob.
|
||||||
|
George would gain 17 happiness units by sitting next to Carol.
|
||||||
|
George would gain 92 happiness units by sitting next to David.
|
||||||
|
George would lose 92 happiness units by sitting next to Eric.
|
||||||
|
George would gain 18 happiness units by sitting next to Frank.
|
||||||
|
George would gain 97 happiness units by sitting next to Mallory.
|
||||||
|
George would gain 0 happiness units by sitting next to Brian.
|
||||||
|
Mallory would gain 92 happiness units by sitting next to Alice.
|
||||||
|
Mallory would lose 96 happiness units by sitting next to Bob.
|
||||||
|
Mallory would lose 51 happiness units by sitting next to Carol.
|
||||||
|
Mallory would lose 81 happiness units by sitting next to David.
|
||||||
|
Mallory would gain 31 happiness units by sitting next to Eric.
|
||||||
|
Mallory would lose 73 happiness units by sitting next to Frank.
|
||||||
|
Mallory would gain 0 happiness units by sitting next to Brian.
|
||||||
|
Mallory would lose 89 happiness units by sitting next to George.
|
||||||
|
Brian would gain 0 happiness units by sitting next to Alice.
|
||||||
|
Brian would gain 0 happiness units by sitting next to Bob.
|
||||||
|
Brian would gain 0 happiness units by sitting next to Carol.
|
||||||
|
Brian would gain 0 happiness units by sitting next to David.
|
||||||
|
Brian would gain 0 happiness units by sitting next to Eric.
|
||||||
|
Brian would gain 0 happiness units by sitting next to Frank.
|
||||||
|
Brian would gain 0 happiness units by sitting next to Mallory.
|
157
2015/day13/main.go
Normal file
157
2015/day13/main.go
Normal file
@ -0,0 +1,157 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bufio"
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
"strconv"
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
|
var people map[string]person
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
var pplSlice []string
|
||||||
|
people = make(map[string]person)
|
||||||
|
var input []string
|
||||||
|
scanner := bufio.NewScanner(os.Stdin)
|
||||||
|
for scanner.Scan() {
|
||||||
|
input = append(input, scanner.Text())
|
||||||
|
}
|
||||||
|
|
||||||
|
for i := range input {
|
||||||
|
p := parseLine(input[i])
|
||||||
|
people[p.name] = p
|
||||||
|
}
|
||||||
|
for i := range people {
|
||||||
|
pplSlice = append(pplSlice, people[i].name)
|
||||||
|
}
|
||||||
|
// Output all preferences
|
||||||
|
/*
|
||||||
|
for k, v := range people {
|
||||||
|
fmt.Println(k)
|
||||||
|
fmt.Println(" High: " + v.highName + " :: " + strconv.Itoa(v.highVal))
|
||||||
|
for pk, pv := range v.prefs {
|
||||||
|
fmt.Println(" " + pk + ": " + strconv.Itoa(pv))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
//getPerms(pplSlice)
|
||||||
|
first := pplSlice[0]
|
||||||
|
res := getPerms(pplSlice[1:])
|
||||||
|
var high int
|
||||||
|
var arrangement []string
|
||||||
|
for i := range res {
|
||||||
|
tstArr := append([]string{first}, res[i]...)
|
||||||
|
tst := happinessFromStrings(tstArr)
|
||||||
|
if tst > high {
|
||||||
|
high = tst
|
||||||
|
arrangement = tstArr
|
||||||
|
}
|
||||||
|
}
|
||||||
|
fmt.Println("Highest: " + strconv.Itoa(high))
|
||||||
|
fmt.Println(arrangement)
|
||||||
|
}
|
||||||
|
|
||||||
|
func getPerms(ppl []string) [][]string {
|
||||||
|
var ret [][]string
|
||||||
|
if len(ppl) == 1 {
|
||||||
|
return append(ret, ppl)
|
||||||
|
}
|
||||||
|
|
||||||
|
for j := range ppl {
|
||||||
|
var bld []string
|
||||||
|
for i := range ppl {
|
||||||
|
if i != j {
|
||||||
|
bld = append(bld, ppl[i])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
perms := getPerms(bld)
|
||||||
|
for i := range perms {
|
||||||
|
perms[i] = append([]string{ppl[j]}, perms[i]...)
|
||||||
|
ret = append(ret, perms[i])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ret
|
||||||
|
}
|
||||||
|
|
||||||
|
func happinessFromStrings(pS []string) int {
|
||||||
|
var ppl []person
|
||||||
|
for i := range pS {
|
||||||
|
ppl = append(ppl, people[pS[i]])
|
||||||
|
}
|
||||||
|
return happinessValue(ppl)
|
||||||
|
}
|
||||||
|
|
||||||
|
func happinessValue(ppl []person) int {
|
||||||
|
var ret int
|
||||||
|
for i := range ppl {
|
||||||
|
p1, p2 := getNeighbors(ppl[i], ppl)
|
||||||
|
ret += ppl[i].prefs[p1.name]
|
||||||
|
ret += ppl[i].prefs[p2.name]
|
||||||
|
}
|
||||||
|
return ret
|
||||||
|
}
|
||||||
|
|
||||||
|
func getNeighbors(p person, ppl []person) (person, person) {
|
||||||
|
var p1, p2 person
|
||||||
|
for idx := range ppl {
|
||||||
|
if ppl[idx].name == p.name {
|
||||||
|
if idx == 0 {
|
||||||
|
p1 = ppl[len(ppl)-1]
|
||||||
|
p2 = ppl[idx+1]
|
||||||
|
} else if idx == len(ppl)-1 {
|
||||||
|
p1 = ppl[idx-1]
|
||||||
|
p2 = ppl[0]
|
||||||
|
} else {
|
||||||
|
p1 = ppl[idx-1]
|
||||||
|
p2 = ppl[idx+1]
|
||||||
|
}
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return p1, p2
|
||||||
|
}
|
||||||
|
|
||||||
|
type person struct {
|
||||||
|
name string
|
||||||
|
prefs map[string]int
|
||||||
|
highName string
|
||||||
|
highVal int
|
||||||
|
lowName string
|
||||||
|
lowVal int
|
||||||
|
}
|
||||||
|
|
||||||
|
func parseLine(s string) person {
|
||||||
|
parts := strings.Split(s, " ")
|
||||||
|
who := parts[0]
|
||||||
|
direction := parts[2]
|
||||||
|
amount := mustAtoi(parts[3])
|
||||||
|
nextTo := parts[10][:len(parts[10])-1]
|
||||||
|
if direction == "lose" {
|
||||||
|
amount = amount * -1
|
||||||
|
}
|
||||||
|
var ret person
|
||||||
|
var ok bool
|
||||||
|
if ret, ok = people[who]; !ok {
|
||||||
|
ret = person{name: who}
|
||||||
|
ret.prefs = make(map[string]int)
|
||||||
|
}
|
||||||
|
ret.prefs[nextTo] = amount
|
||||||
|
if ret.highVal < amount || ret.highName == "" {
|
||||||
|
ret.highVal, ret.highName = amount, nextTo
|
||||||
|
}
|
||||||
|
if ret.lowVal > amount || ret.lowName == "" {
|
||||||
|
ret.lowVal, ret.lowName = amount, nextTo
|
||||||
|
}
|
||||||
|
return ret
|
||||||
|
}
|
||||||
|
|
||||||
|
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
|
||||||
|
}
|
96
2015/day13/problem
Normal file
96
2015/day13/problem
Normal file
@ -0,0 +1,96 @@
|
|||||||
|
Advent of Code
|
||||||
|
|
||||||
|
br0xen 40*
|
||||||
|
|
||||||
|
• [About]
|
||||||
|
• [Stats]
|
||||||
|
• [Leaderboard]
|
||||||
|
• [Settings]
|
||||||
|
• [Log out]
|
||||||
|
|
||||||
|
--- Day 13: Knights of the Dinner Table ---
|
||||||
|
|
||||||
|
In years past, the holiday feast with your family hasn't gone so well. Not everyone gets along!
|
||||||
|
This year, you resolve, will be different. You're going to find the optimal seating arrangement
|
||||||
|
and avoid all those awkward conversations.
|
||||||
|
|
||||||
|
You start by writing up a list of everyone invited and the amount their happiness would
|
||||||
|
increase or decrease if they were to find themselves sitting next to each other person. You
|
||||||
|
have a circular table that will be just big enough to fit everyone comfortably, and so each
|
||||||
|
person will have exactly two neighbors.
|
||||||
|
|
||||||
|
For example, suppose you have only four attendees planned, and you calculate their potential
|
||||||
|
happiness as follows:
|
||||||
|
|
||||||
|
Alice would gain 54 happiness units by sitting next to Bob.
|
||||||
|
Alice would lose 79 happiness units by sitting next to Carol.
|
||||||
|
Alice would lose 2 happiness units by sitting next to David.
|
||||||
|
Bob would gain 83 happiness units by sitting next to Alice.
|
||||||
|
Bob would lose 7 happiness units by sitting next to Carol.
|
||||||
|
Bob would lose 63 happiness units by sitting next to David.
|
||||||
|
Carol would lose 62 happiness units by sitting next to Alice.
|
||||||
|
Carol would gain 60 happiness units by sitting next to Bob.
|
||||||
|
Carol would gain 55 happiness units by sitting next to David.
|
||||||
|
David would gain 46 happiness units by sitting next to Alice.
|
||||||
|
David would lose 7 happiness units by sitting next to Bob.
|
||||||
|
David would gain 41 happiness units by sitting next to Carol.
|
||||||
|
|
||||||
|
Then, if you seat Alice next to David, Alice would lose 2 happiness units (because David talks
|
||||||
|
so much), but David would gain 46 happiness units (because Alice is such a good listener), for
|
||||||
|
a total change of 44.
|
||||||
|
|
||||||
|
If you continue around the table, you could then seat Bob next to Alice (Bob gains 83, Alice
|
||||||
|
gains 54). Finally, seat Carol, who sits next to Bob (Carol gains 60, Bob loses 7) and David
|
||||||
|
(Carol gains 55, David gains 41). The arrangement looks like this:
|
||||||
|
|
||||||
|
+41 +46
|
||||||
|
+55 David -2
|
||||||
|
Carol Alice
|
||||||
|
+60 Bob +54
|
||||||
|
-7 +83
|
||||||
|
|
||||||
|
After trying every other seating arrangement in this hypothetical scenario, you find that this
|
||||||
|
one is the most optimal, with a total change in happiness of 330.
|
||||||
|
|
||||||
|
What is the total change in happiness for the optimal seating arrangement of the actual guest
|
||||||
|
list?
|
||||||
|
|
||||||
|
Your puzzle answer was 733.
|
||||||
|
|
||||||
|
--- Part Two ---
|
||||||
|
|
||||||
|
In all the commotion, you realize that you forgot to seat yourself. At this point, you're
|
||||||
|
pretty apathetic toward the whole thing, and your happiness wouldn't really go up or down
|
||||||
|
regardless of who you sit next to. You assume everyone else would be just as ambivalent about
|
||||||
|
sitting next to you, too.
|
||||||
|
|
||||||
|
So, add yourself to the list, and give all happiness relationships that involve you a score of
|
||||||
|
0.
|
||||||
|
|
||||||
|
What is the total change in happiness for the optimal seating arrangement that actually
|
||||||
|
includes yourself?
|
||||||
|
|
||||||
|
Your puzzle answer was 725.
|
||||||
|
|
||||||
|
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/13/input
|
||||||
|
. https://twitter.com/intent/tweet?text=I%27ve+completed+%22Knights+of+the+Dinner+Table%22+%2D+Day+13+%2D+Advent+of+Code&url=http%3A%2F%2Fadventofcode%2Ecom%2Fday%2F13&related=ericwastl&hashtags=AdventOfCode
|
||||||
|
. https://plus.google.com/share?url=http%3A%2F%2Fadventofcode%2Ecom%2Fday%2F13
|
||||||
|
. http://www.reddit.com/submit?url=http%3A%2F%2Fadventofcode%2Ecom%2Fday%2F13&title=I%27ve+completed+%22Knights+of+the+Dinner+Table%22+%2D+Day+13+%2D+Advent+of+Code
|
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.
|
4
2015/day15/input
Normal file
4
2015/day15/input
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
Frosting: capacity 4, durability -2, flavor 0, texture 0, calories 5
|
||||||
|
Candy: capacity 0, durability 5, flavor -1, texture 0, calories 8
|
||||||
|
Butterscotch: capacity -1, durability 0, flavor 5, texture 0, calories 6
|
||||||
|
Sugar: capacity 0, durability 0, flavor -2, texture 2, calories 1
|
156
2015/day15/main.go
Normal file
156
2015/day15/main.go
Normal file
@ -0,0 +1,156 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bufio"
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
"strconv"
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
|
var ings []ingredient
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
var input []string
|
||||||
|
scanner := bufio.NewScanner(os.Stdin)
|
||||||
|
for scanner.Scan() {
|
||||||
|
input = append(input, scanner.Text())
|
||||||
|
}
|
||||||
|
|
||||||
|
var stringIngs []string
|
||||||
|
total := 100
|
||||||
|
for i := range input {
|
||||||
|
bldI := *createIngredient(input[i])
|
||||||
|
ings = append(ings, bldI)
|
||||||
|
stringIngs = append(stringIngs, bldI.name)
|
||||||
|
}
|
||||||
|
|
||||||
|
combis := getIntCombis(total, len(stringIngs))
|
||||||
|
ingPerms := getStringPermus(stringIngs)
|
||||||
|
|
||||||
|
var highVal int
|
||||||
|
var highMap map[string]int
|
||||||
|
for h := range combis {
|
||||||
|
for i := range ingPerms {
|
||||||
|
tstMap := make(map[string]int)
|
||||||
|
for j := range ingPerms[i] {
|
||||||
|
tstMap[ingPerms[i][j]] = combis[h][j]
|
||||||
|
}
|
||||||
|
tmp, cals := calcValue(tstMap)
|
||||||
|
if cals == 500 && tmp > highVal {
|
||||||
|
highVal = tmp
|
||||||
|
highMap = tstMap
|
||||||
|
|
||||||
|
fmt.Print(strconv.Itoa(tmp))
|
||||||
|
fmt.Print(" :: ")
|
||||||
|
fmt.Println(tstMap)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
fmt.Println()
|
||||||
|
fmt.Println(highMap)
|
||||||
|
fmt.Println("Highest Value: " + strconv.Itoa(highVal))
|
||||||
|
}
|
||||||
|
|
||||||
|
func getStringPermus(vals []string) [][]string {
|
||||||
|
var ret [][]string
|
||||||
|
if len(vals) == 1 {
|
||||||
|
return append(ret, vals)
|
||||||
|
}
|
||||||
|
|
||||||
|
for j := range vals {
|
||||||
|
var bld []string
|
||||||
|
for i := range vals {
|
||||||
|
if i != j {
|
||||||
|
bld = append(bld, vals[i])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
tmp := getStringPermus(bld)
|
||||||
|
for i := range tmp {
|
||||||
|
tmp[i] = append([]string{vals[j]}, tmp[i]...)
|
||||||
|
ret = append(ret, tmp[i])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ret
|
||||||
|
}
|
||||||
|
|
||||||
|
func getIntCombis(total, containers int) [][]int {
|
||||||
|
var ret [][]int
|
||||||
|
if containers == 2 {
|
||||||
|
for i := total; i >= 0; i-- { //(total / 2); i-- {
|
||||||
|
ret = append(ret, []int{i, (total - i)})
|
||||||
|
}
|
||||||
|
return ret
|
||||||
|
}
|
||||||
|
for i := total; i >= 0; i-- { //(total / 2); i-- {
|
||||||
|
tmp := getIntCombis((total - i), (containers - 1))
|
||||||
|
for j := 0; j < len(tmp); j++ {
|
||||||
|
tmp[j] = append([]int{i}, tmp[j]...)
|
||||||
|
ret = append(ret, tmp[j])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ret
|
||||||
|
}
|
||||||
|
|
||||||
|
func getIngredient(name string) *ingredient {
|
||||||
|
for i := range ings {
|
||||||
|
if ings[i].name == name {
|
||||||
|
return &ings[i]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func calcValue(list map[string]int) (int, int) {
|
||||||
|
tmp := new(ingredient)
|
||||||
|
for kname, v := range list {
|
||||||
|
k := getIngredient(kname)
|
||||||
|
tmp.capacity += k.capacity * v
|
||||||
|
tmp.durability += k.durability * v
|
||||||
|
tmp.flavor += k.flavor * v
|
||||||
|
tmp.texture += k.texture * v
|
||||||
|
tmp.calories += k.calories * v
|
||||||
|
}
|
||||||
|
if tmp.texture < 0 || tmp.durability < 0 || tmp.flavor < 0 || tmp.texture < 0 {
|
||||||
|
return 0, 0
|
||||||
|
}
|
||||||
|
return (tmp.capacity * tmp.durability * tmp.flavor * tmp.texture), tmp.calories
|
||||||
|
}
|
||||||
|
|
||||||
|
type ingredient struct {
|
||||||
|
name string
|
||||||
|
capacity int
|
||||||
|
durability int
|
||||||
|
flavor int
|
||||||
|
texture int
|
||||||
|
calories int
|
||||||
|
}
|
||||||
|
|
||||||
|
func createIngredient(s string) *ingredient {
|
||||||
|
parts := strings.Split(s, " ")
|
||||||
|
name := parts[0]
|
||||||
|
name = name[:len(name)-1]
|
||||||
|
c := parts[2]
|
||||||
|
d := parts[4]
|
||||||
|
f := parts[6]
|
||||||
|
t := parts[8]
|
||||||
|
cal := parts[10]
|
||||||
|
i := ingredient{
|
||||||
|
name: name,
|
||||||
|
capacity: mustAtoi(c[:len(c)-1]),
|
||||||
|
durability: mustAtoi(d[:len(d)-1]),
|
||||||
|
flavor: mustAtoi(f[:len(f)-1]),
|
||||||
|
texture: mustAtoi(t[:len(t)-1]),
|
||||||
|
calories: mustAtoi(cal),
|
||||||
|
}
|
||||||
|
return &i
|
||||||
|
}
|
||||||
|
|
||||||
|
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
|
||||||
|
}
|
92
2015/day15/problem
Normal file
92
2015/day15/problem
Normal file
@ -0,0 +1,92 @@
|
|||||||
|
Advent of Code
|
||||||
|
|
||||||
|
br0xen 40*
|
||||||
|
|
||||||
|
• [About]
|
||||||
|
• [Stats]
|
||||||
|
• [Leaderboard]
|
||||||
|
• [Settings]
|
||||||
|
• [Log out]
|
||||||
|
|
||||||
|
--- Day 15: Science for Hungry People ---
|
||||||
|
|
||||||
|
Today, you set out on the task of perfecting your milk-dunking cookie recipe. All you have to
|
||||||
|
do is find the right balance of ingredients.
|
||||||
|
|
||||||
|
Your recipe leaves room for exactly 100 teaspoons of ingredients. You make a list of the
|
||||||
|
remaining ingredients you could use to finish the recipe (your puzzle input) and their
|
||||||
|
properties per teaspoon:
|
||||||
|
|
||||||
|
• capacity (how well it helps the cookie absorb milk)
|
||||||
|
• durability (how well it keeps the cookie intact when full of milk)
|
||||||
|
• flavor (how tasty it makes the cookie)
|
||||||
|
• texture (how it improves the feel of the cookie)
|
||||||
|
• calories (how many calories it adds to the cookie)
|
||||||
|
|
||||||
|
You can only measure ingredients in whole-teaspoon amounts accurately, and you have to be
|
||||||
|
accurate so you can reproduce your results in the future. The total score of a cookie can be
|
||||||
|
found by adding up each of the properties (negative totals become 0) and then multiplying
|
||||||
|
together everything except calories.
|
||||||
|
|
||||||
|
For instance, suppose you have these two ingredients:
|
||||||
|
|
||||||
|
Butterscotch: capacity -1, durability -2, flavor 6, texture 3, calories 8
|
||||||
|
Cinnamon: capacity 2, durability 3, flavor -2, texture -1, calories 3
|
||||||
|
|
||||||
|
Then, choosing to use 44 teaspoons of butterscotch and 56 teaspoons of cinnamon (because the
|
||||||
|
amounts of each ingredient must add up to 100) would result in a cookie with the following
|
||||||
|
properties:
|
||||||
|
|
||||||
|
• A capacity of 44*-1 + 56*2 = 68
|
||||||
|
• A durability of 44*-2 + 56*3 = 80
|
||||||
|
• A flavor of 44*6 + 56*-2 = 152
|
||||||
|
• A texture of 44*3 + 56*-1 = 76
|
||||||
|
|
||||||
|
Multiplying these together (68 * 80 * 152 * 76, ignoring calories for now) results in a total
|
||||||
|
score of 62842880, which happens to be the best score possible given these ingredients. If any
|
||||||
|
properties had produced a negative total, it would have instead become zero, causing the whole
|
||||||
|
score to multiply to zero.
|
||||||
|
|
||||||
|
Given the ingredients in your kitchen and their properties, what is the total score of the
|
||||||
|
highest-scoring cookie you can make?
|
||||||
|
|
||||||
|
Your puzzle answer was 18965440.
|
||||||
|
|
||||||
|
--- Part Two ---
|
||||||
|
|
||||||
|
Your cookie recipe becomes wildly popular! Someone asks if you can make another recipe that has
|
||||||
|
exactly 500 calories per cookie (so they can use it as a meal replacement). Keep the rest of
|
||||||
|
your award-winning process the same (100 teaspoons, same ingredients, same scoring system).
|
||||||
|
|
||||||
|
For example, given the ingredients above, if you had instead selected 40 teaspoons of
|
||||||
|
butterscotch and 60 teaspoons of cinnamon (which still adds to 100), the total calorie count
|
||||||
|
would be 40*8 + 60*3 = 500. The total score would go down, though: only 57600000, the best you
|
||||||
|
can do in such trying circumstances.
|
||||||
|
|
||||||
|
Given the ingredients in your kitchen and their properties, what is the total score of the
|
||||||
|
highest-scoring cookie you can make with a calorie total of 500?
|
||||||
|
|
||||||
|
Your puzzle answer was 15862900.
|
||||||
|
|
||||||
|
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/15/input
|
||||||
|
. https://twitter.com/intent/tweet?text=I%27ve+completed+%22Science+for+Hungry+People%22+%2D+Day+15+%2D+Advent+of+Code&url=http%3A%2F%2Fadventofcode%2Ecom%2Fday%2F15&related=ericwastl&hashtags=AdventOfCode
|
||||||
|
. https://plus.google.com/share?url=http%3A%2F%2Fadventofcode%2Ecom%2Fday%2F15
|
||||||
|
. http://www.reddit.com/submit?url=http%3A%2F%2Fadventofcode%2Ecom%2Fday%2F15&title=I%27ve+completed+%22Science+for+Hungry+People%22+%2D+Day+15+%2D+Advent+of+Code
|
2
2015/day15/sample_input
Normal file
2
2015/day15/sample_input
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
B: c -1, dur -2, flav 6, tex 3, cal 8
|
||||||
|
C: c 2, dur 3, flav -2, tex -1, cal 3
|
500
2015/day16/input
Normal file
500
2015/day16/input
Normal file
@ -0,0 +1,500 @@
|
|||||||
|
Sue 1: cars: 9, akitas: 3, goldfish: 0
|
||||||
|
Sue 2: akitas: 9, children: 3, samoyeds: 9
|
||||||
|
Sue 3: trees: 6, cars: 6, children: 4
|
||||||
|
Sue 4: trees: 4, vizslas: 4, goldfish: 9
|
||||||
|
Sue 5: akitas: 9, vizslas: 7, cars: 5
|
||||||
|
Sue 6: vizslas: 6, goldfish: 6, akitas: 3
|
||||||
|
Sue 7: pomeranians: 5, samoyeds: 0, perfumes: 10
|
||||||
|
Sue 8: cars: 10, pomeranians: 7, goldfish: 8
|
||||||
|
Sue 9: trees: 2, vizslas: 7, samoyeds: 6
|
||||||
|
Sue 10: perfumes: 5, pomeranians: 4, children: 9
|
||||||
|
Sue 11: vizslas: 5, perfumes: 8, cars: 10
|
||||||
|
Sue 12: children: 10, cars: 6, perfumes: 5
|
||||||
|
Sue 13: cats: 4, samoyeds: 7, pomeranians: 8
|
||||||
|
Sue 14: perfumes: 6, goldfish: 10, children: 7
|
||||||
|
Sue 15: perfumes: 4, pomeranians: 3, cars: 6
|
||||||
|
Sue 16: perfumes: 7, cars: 9, pomeranians: 6
|
||||||
|
Sue 17: goldfish: 3, cars: 6, vizslas: 7
|
||||||
|
Sue 18: perfumes: 6, cars: 7, goldfish: 3
|
||||||
|
Sue 19: trees: 0, akitas: 3, pomeranians: 8
|
||||||
|
Sue 20: goldfish: 6, trees: 2, akitas: 6
|
||||||
|
Sue 21: pomeranians: 9, akitas: 9, samoyeds: 9
|
||||||
|
Sue 22: vizslas: 2, cars: 9, perfumes: 5
|
||||||
|
Sue 23: goldfish: 10, samoyeds: 8, children: 9
|
||||||
|
Sue 24: akitas: 4, goldfish: 1, vizslas: 5
|
||||||
|
Sue 25: goldfish: 10, trees: 8, perfumes: 6
|
||||||
|
Sue 26: vizslas: 5, akitas: 8, trees: 1
|
||||||
|
Sue 27: trees: 3, cars: 6, perfumes: 2
|
||||||
|
Sue 28: goldfish: 8, trees: 7, akitas: 10
|
||||||
|
Sue 29: children: 5, trees: 1, goldfish: 10
|
||||||
|
Sue 30: vizslas: 3, perfumes: 8, akitas: 3
|
||||||
|
Sue 31: cars: 6, children: 10, perfumes: 7
|
||||||
|
Sue 32: cars: 10, perfumes: 3, goldfish: 10
|
||||||
|
Sue 33: perfumes: 9, vizslas: 3, akitas: 4
|
||||||
|
Sue 34: perfumes: 10, vizslas: 7, children: 8
|
||||||
|
Sue 35: cars: 5, perfumes: 5, vizslas: 9
|
||||||
|
Sue 36: trees: 9, cars: 9, akitas: 7
|
||||||
|
Sue 37: samoyeds: 9, perfumes: 2, cars: 10
|
||||||
|
Sue 38: akitas: 7, cars: 5, trees: 5
|
||||||
|
Sue 39: goldfish: 8, trees: 9, cars: 10
|
||||||
|
Sue 40: trees: 0, cats: 1, pomeranians: 1
|
||||||
|
Sue 41: pomeranians: 6, perfumes: 9, samoyeds: 1
|
||||||
|
Sue 42: vizslas: 6, akitas: 3, pomeranians: 1
|
||||||
|
Sue 43: vizslas: 2, perfumes: 3, pomeranians: 6
|
||||||
|
Sue 44: akitas: 5, pomeranians: 0, vizslas: 10
|
||||||
|
Sue 45: vizslas: 4, goldfish: 1, cars: 5
|
||||||
|
Sue 46: cars: 4, vizslas: 8, cats: 0
|
||||||
|
Sue 47: cats: 5, children: 8, pomeranians: 2
|
||||||
|
Sue 48: vizslas: 3, perfumes: 6, cats: 0
|
||||||
|
Sue 49: akitas: 7, perfumes: 0, trees: 7
|
||||||
|
Sue 50: trees: 4, akitas: 10, vizslas: 2
|
||||||
|
Sue 51: goldfish: 10, cars: 9, trees: 4
|
||||||
|
Sue 52: cars: 5, children: 9, perfumes: 0
|
||||||
|
Sue 53: vizslas: 5, cars: 3, cats: 8
|
||||||
|
Sue 54: cars: 5, akitas: 1, goldfish: 10
|
||||||
|
Sue 55: akitas: 10, vizslas: 2, cars: 6
|
||||||
|
Sue 56: cats: 6, trees: 0, cars: 4
|
||||||
|
Sue 57: vizslas: 1, akitas: 1, samoyeds: 7
|
||||||
|
Sue 58: samoyeds: 6, vizslas: 1, akitas: 7
|
||||||
|
Sue 59: akitas: 9, cars: 8, vizslas: 1
|
||||||
|
Sue 60: cars: 6, vizslas: 7, goldfish: 0
|
||||||
|
Sue 61: pomeranians: 5, akitas: 6, vizslas: 2
|
||||||
|
Sue 62: samoyeds: 2, cats: 8, goldfish: 7
|
||||||
|
Sue 63: vizslas: 10, goldfish: 7, samoyeds: 9
|
||||||
|
Sue 64: perfumes: 2, trees: 1, akitas: 6
|
||||||
|
Sue 65: cars: 8, perfumes: 10, vizslas: 9
|
||||||
|
Sue 66: akitas: 8, vizslas: 8, perfumes: 8
|
||||||
|
Sue 67: goldfish: 7, cars: 9, samoyeds: 9
|
||||||
|
Sue 68: perfumes: 2, children: 7, akitas: 1
|
||||||
|
Sue 69: perfumes: 7, vizslas: 9, akitas: 1
|
||||||
|
Sue 70: samoyeds: 3, vizslas: 1, trees: 1
|
||||||
|
Sue 71: vizslas: 8, goldfish: 7, trees: 9
|
||||||
|
Sue 72: goldfish: 8, cars: 6, trees: 9
|
||||||
|
Sue 73: perfumes: 5, cars: 10, samoyeds: 7
|
||||||
|
Sue 74: pomeranians: 4, perfumes: 3, cars: 5
|
||||||
|
Sue 75: samoyeds: 1, perfumes: 1, pomeranians: 1
|
||||||
|
Sue 76: goldfish: 4, cats: 6, akitas: 7
|
||||||
|
Sue 77: perfumes: 5, akitas: 4, vizslas: 8
|
||||||
|
Sue 78: perfumes: 4, cats: 3, children: 4
|
||||||
|
Sue 79: vizslas: 5, pomeranians: 9, samoyeds: 7
|
||||||
|
Sue 80: cars: 3, samoyeds: 5, pomeranians: 7
|
||||||
|
Sue 81: vizslas: 2, samoyeds: 4, perfumes: 2
|
||||||
|
Sue 82: trees: 1, akitas: 10, vizslas: 9
|
||||||
|
Sue 83: vizslas: 0, akitas: 2, samoyeds: 5
|
||||||
|
Sue 84: perfumes: 5, vizslas: 7, children: 8
|
||||||
|
Sue 85: cats: 3, children: 2, trees: 0
|
||||||
|
Sue 86: cars: 3, perfumes: 2, goldfish: 2
|
||||||
|
Sue 87: trees: 1, akitas: 7, vizslas: 0
|
||||||
|
Sue 88: trees: 1, akitas: 2, samoyeds: 1
|
||||||
|
Sue 89: cars: 4, vizslas: 8, akitas: 1
|
||||||
|
Sue 90: perfumes: 5, cats: 3, vizslas: 0
|
||||||
|
Sue 91: samoyeds: 7, cats: 6, goldfish: 8
|
||||||
|
Sue 92: samoyeds: 10, cats: 0, cars: 7
|
||||||
|
Sue 93: cars: 6, akitas: 7, samoyeds: 2
|
||||||
|
Sue 94: perfumes: 0, goldfish: 6, trees: 9
|
||||||
|
Sue 95: cars: 6, pomeranians: 2, samoyeds: 8
|
||||||
|
Sue 96: cars: 2, trees: 9, samoyeds: 4
|
||||||
|
Sue 97: goldfish: 5, trees: 1, children: 0
|
||||||
|
Sue 98: akitas: 9, goldfish: 7, children: 6
|
||||||
|
Sue 99: goldfish: 9, akitas: 0, pomeranians: 0
|
||||||
|
Sue 100: samoyeds: 6, children: 8, vizslas: 5
|
||||||
|
Sue 101: vizslas: 6, cars: 5, goldfish: 4
|
||||||
|
Sue 102: vizslas: 6, akitas: 2, perfumes: 6
|
||||||
|
Sue 103: samoyeds: 3, akitas: 7, children: 4
|
||||||
|
Sue 104: cars: 3, perfumes: 10, cats: 6
|
||||||
|
Sue 105: vizslas: 9, pomeranians: 0, cars: 1
|
||||||
|
Sue 106: cats: 6, samoyeds: 8, pomeranians: 5
|
||||||
|
Sue 107: cars: 7, trees: 4, akitas: 10
|
||||||
|
Sue 108: perfumes: 3, vizslas: 1, goldfish: 9
|
||||||
|
Sue 109: trees: 6, cars: 8, goldfish: 5
|
||||||
|
Sue 110: pomeranians: 2, children: 1, vizslas: 7
|
||||||
|
Sue 111: akitas: 0, vizslas: 8, cars: 0
|
||||||
|
Sue 112: goldfish: 3, vizslas: 6, akitas: 2
|
||||||
|
Sue 113: akitas: 10, pomeranians: 7, perfumes: 7
|
||||||
|
Sue 114: cars: 10, cats: 2, vizslas: 8
|
||||||
|
Sue 115: akitas: 8, trees: 1, vizslas: 2
|
||||||
|
Sue 116: vizslas: 2, akitas: 7, perfumes: 1
|
||||||
|
Sue 117: goldfish: 0, vizslas: 10, trees: 9
|
||||||
|
Sue 118: trees: 3, cars: 0, goldfish: 0
|
||||||
|
Sue 119: perfumes: 7, goldfish: 5, trees: 9
|
||||||
|
Sue 120: children: 9, vizslas: 3, trees: 5
|
||||||
|
Sue 121: vizslas: 1, goldfish: 7, akitas: 10
|
||||||
|
Sue 122: perfumes: 1, cars: 6, trees: 1
|
||||||
|
Sue 123: akitas: 2, vizslas: 0, goldfish: 7
|
||||||
|
Sue 124: vizslas: 10, pomeranians: 7, akitas: 0
|
||||||
|
Sue 125: perfumes: 4, cats: 5, vizslas: 2
|
||||||
|
Sue 126: cars: 6, samoyeds: 8, akitas: 3
|
||||||
|
Sue 127: trees: 9, goldfish: 7, akitas: 9
|
||||||
|
Sue 128: cars: 8, trees: 0, perfumes: 2
|
||||||
|
Sue 129: pomeranians: 7, vizslas: 2, perfumes: 6
|
||||||
|
Sue 130: vizslas: 9, pomeranians: 3, trees: 6
|
||||||
|
Sue 131: vizslas: 7, cars: 9, perfumes: 1
|
||||||
|
Sue 132: akitas: 2, pomeranians: 9, vizslas: 7
|
||||||
|
Sue 133: trees: 9, pomeranians: 10, samoyeds: 0
|
||||||
|
Sue 134: children: 4, akitas: 10, perfumes: 4
|
||||||
|
Sue 135: vizslas: 1, cats: 1, trees: 8
|
||||||
|
Sue 136: samoyeds: 7, cars: 8, goldfish: 5
|
||||||
|
Sue 137: perfumes: 0, children: 1, pomeranians: 10
|
||||||
|
Sue 138: vizslas: 4, perfumes: 5, cars: 5
|
||||||
|
Sue 139: trees: 2, perfumes: 8, goldfish: 0
|
||||||
|
Sue 140: cars: 10, akitas: 5, goldfish: 7
|
||||||
|
Sue 141: children: 4, trees: 3, goldfish: 8
|
||||||
|
Sue 142: cars: 8, perfumes: 6, trees: 7
|
||||||
|
Sue 143: akitas: 6, goldfish: 0, trees: 10
|
||||||
|
Sue 144: akitas: 7, pomeranians: 10, perfumes: 10
|
||||||
|
Sue 145: trees: 10, vizslas: 3, goldfish: 4
|
||||||
|
Sue 146: samoyeds: 4, akitas: 3, perfumes: 6
|
||||||
|
Sue 147: akitas: 8, perfumes: 2, pomeranians: 10
|
||||||
|
Sue 148: cars: 2, perfumes: 0, goldfish: 8
|
||||||
|
Sue 149: goldfish: 6, akitas: 7, perfumes: 6
|
||||||
|
Sue 150: cars: 2, pomeranians: 5, perfumes: 4
|
||||||
|
Sue 151: goldfish: 1, cars: 5, trees: 0
|
||||||
|
Sue 152: pomeranians: 4, cars: 7, children: 1
|
||||||
|
Sue 153: goldfish: 8, cars: 1, children: 10
|
||||||
|
Sue 154: cars: 6, perfumes: 8, trees: 1
|
||||||
|
Sue 155: akitas: 4, perfumes: 6, pomeranians: 2
|
||||||
|
Sue 156: pomeranians: 5, cars: 4, akitas: 1
|
||||||
|
Sue 157: cats: 5, cars: 9, goldfish: 8
|
||||||
|
Sue 158: vizslas: 5, samoyeds: 1, children: 7
|
||||||
|
Sue 159: vizslas: 1, perfumes: 3, akitas: 1
|
||||||
|
Sue 160: goldfish: 10, pomeranians: 9, perfumes: 5
|
||||||
|
Sue 161: samoyeds: 3, trees: 7, cars: 2
|
||||||
|
Sue 162: cars: 2, pomeranians: 1, vizslas: 6
|
||||||
|
Sue 163: vizslas: 3, perfumes: 5, akitas: 6
|
||||||
|
Sue 164: vizslas: 1, trees: 0, akitas: 5
|
||||||
|
Sue 165: vizslas: 5, cars: 6, pomeranians: 8
|
||||||
|
Sue 166: cars: 10, perfumes: 2, trees: 9
|
||||||
|
Sue 167: cars: 10, pomeranians: 6, perfumes: 4
|
||||||
|
Sue 168: akitas: 7, trees: 10, goldfish: 7
|
||||||
|
Sue 169: akitas: 1, perfumes: 10, cars: 10
|
||||||
|
Sue 170: akitas: 5, samoyeds: 8, vizslas: 6
|
||||||
|
Sue 171: children: 3, akitas: 2, vizslas: 3
|
||||||
|
Sue 172: goldfish: 5, vizslas: 5, perfumes: 9
|
||||||
|
Sue 173: perfumes: 5, goldfish: 10, trees: 5
|
||||||
|
Sue 174: akitas: 5, vizslas: 2, children: 7
|
||||||
|
Sue 175: perfumes: 5, cars: 7, samoyeds: 2
|
||||||
|
Sue 176: cars: 8, vizslas: 10, akitas: 7
|
||||||
|
Sue 177: perfumes: 7, children: 8, goldfish: 7
|
||||||
|
Sue 178: cars: 1, pomeranians: 9, samoyeds: 0
|
||||||
|
Sue 179: perfumes: 6, cars: 2, trees: 6
|
||||||
|
Sue 180: trees: 3, vizslas: 7, children: 3
|
||||||
|
Sue 181: vizslas: 8, samoyeds: 2, trees: 9
|
||||||
|
Sue 182: perfumes: 3, cats: 1, children: 5
|
||||||
|
Sue 183: akitas: 9, cats: 6, children: 3
|
||||||
|
Sue 184: pomeranians: 9, cars: 6, perfumes: 8
|
||||||
|
Sue 185: vizslas: 9, trees: 0, akitas: 9
|
||||||
|
Sue 186: perfumes: 6, cars: 5, goldfish: 5
|
||||||
|
Sue 187: perfumes: 4, cats: 7, vizslas: 2
|
||||||
|
Sue 188: akitas: 7, cars: 4, children: 10
|
||||||
|
Sue 189: akitas: 0, goldfish: 7, vizslas: 5
|
||||||
|
Sue 190: akitas: 5, cars: 5, cats: 6
|
||||||
|
Sue 191: cars: 6, children: 0, perfumes: 3
|
||||||
|
Sue 192: cats: 2, perfumes: 10, goldfish: 7
|
||||||
|
Sue 193: trees: 1, perfumes: 0, cars: 8
|
||||||
|
Sue 194: perfumes: 9, children: 4, cats: 6
|
||||||
|
Sue 195: akitas: 7, trees: 3, goldfish: 6
|
||||||
|
Sue 196: goldfish: 8, cars: 8, samoyeds: 0
|
||||||
|
Sue 197: cats: 0, akitas: 10, vizslas: 0
|
||||||
|
Sue 198: goldfish: 1, perfumes: 3, cars: 8
|
||||||
|
Sue 199: akitas: 10, vizslas: 5, samoyeds: 6
|
||||||
|
Sue 200: pomeranians: 9, goldfish: 9, samoyeds: 7
|
||||||
|
Sue 201: samoyeds: 0, goldfish: 7, akitas: 6
|
||||||
|
Sue 202: vizslas: 0, goldfish: 2, akitas: 1
|
||||||
|
Sue 203: goldfish: 3, children: 0, vizslas: 8
|
||||||
|
Sue 204: cars: 8, trees: 2, perfumes: 2
|
||||||
|
Sue 205: cars: 4, perfumes: 5, goldfish: 8
|
||||||
|
Sue 206: vizslas: 3, trees: 2, akitas: 1
|
||||||
|
Sue 207: cars: 7, goldfish: 5, trees: 1
|
||||||
|
Sue 208: goldfish: 1, cars: 6, vizslas: 8
|
||||||
|
Sue 209: cats: 4, trees: 1, children: 0
|
||||||
|
Sue 210: cats: 10, children: 0, perfumes: 0
|
||||||
|
Sue 211: cars: 4, pomeranians: 7, samoyeds: 5
|
||||||
|
Sue 212: cars: 2, pomeranians: 10, trees: 1
|
||||||
|
Sue 213: trees: 10, cats: 5, cars: 10
|
||||||
|
Sue 214: perfumes: 5, trees: 1, vizslas: 1
|
||||||
|
Sue 215: akitas: 10, vizslas: 8, samoyeds: 8
|
||||||
|
Sue 216: vizslas: 2, cats: 5, pomeranians: 3
|
||||||
|
Sue 217: akitas: 10, perfumes: 0, cats: 10
|
||||||
|
Sue 218: trees: 8, cats: 5, vizslas: 2
|
||||||
|
Sue 219: goldfish: 10, perfumes: 8, children: 2
|
||||||
|
Sue 220: samoyeds: 9, trees: 8, vizslas: 7
|
||||||
|
Sue 221: children: 7, trees: 6, cars: 6
|
||||||
|
Sue 222: cats: 4, akitas: 5, pomeranians: 0
|
||||||
|
Sue 223: trees: 8, goldfish: 2, perfumes: 8
|
||||||
|
Sue 224: pomeranians: 9, cars: 8, akitas: 5
|
||||||
|
Sue 225: akitas: 10, vizslas: 0, trees: 2
|
||||||
|
Sue 226: akitas: 8, cats: 6, cars: 7
|
||||||
|
Sue 227: trees: 1, akitas: 3, goldfish: 4
|
||||||
|
Sue 228: pomeranians: 6, cats: 3, goldfish: 3
|
||||||
|
Sue 229: trees: 10, perfumes: 3, vizslas: 7
|
||||||
|
Sue 230: perfumes: 8, cars: 7, akitas: 0
|
||||||
|
Sue 231: perfumes: 10, goldfish: 4, cars: 6
|
||||||
|
Sue 232: goldfish: 7, trees: 3, cats: 2
|
||||||
|
Sue 233: perfumes: 6, trees: 4, akitas: 4
|
||||||
|
Sue 234: goldfish: 9, cats: 4, cars: 7
|
||||||
|
Sue 235: pomeranians: 6, vizslas: 0, akitas: 6
|
||||||
|
Sue 236: samoyeds: 5, cars: 5, children: 4
|
||||||
|
Sue 237: vizslas: 10, cars: 4, goldfish: 4
|
||||||
|
Sue 238: goldfish: 3, samoyeds: 7, akitas: 2
|
||||||
|
Sue 239: cats: 8, children: 2, vizslas: 7
|
||||||
|
Sue 240: cars: 9, perfumes: 4, trees: 9
|
||||||
|
Sue 241: trees: 8, vizslas: 2, goldfish: 5
|
||||||
|
Sue 242: cars: 6, trees: 3, vizslas: 3
|
||||||
|
Sue 243: cats: 6, children: 7, cars: 4
|
||||||
|
Sue 244: cats: 10, perfumes: 2, goldfish: 7
|
||||||
|
Sue 245: akitas: 8, cats: 10, perfumes: 8
|
||||||
|
Sue 246: vizslas: 8, akitas: 5, perfumes: 10
|
||||||
|
Sue 247: goldfish: 2, vizslas: 5, akitas: 7
|
||||||
|
Sue 248: akitas: 3, perfumes: 0, trees: 10
|
||||||
|
Sue 249: cats: 4, vizslas: 5, pomeranians: 6
|
||||||
|
Sue 250: children: 3, vizslas: 7, perfumes: 2
|
||||||
|
Sue 251: cars: 0, pomeranians: 10, perfumes: 0
|
||||||
|
Sue 252: akitas: 0, goldfish: 9, cars: 6
|
||||||
|
Sue 253: perfumes: 7, cars: 4, samoyeds: 5
|
||||||
|
Sue 254: akitas: 9, trees: 10, cars: 4
|
||||||
|
Sue 255: samoyeds: 10, children: 6, akitas: 7
|
||||||
|
Sue 256: trees: 8, goldfish: 8, perfumes: 8
|
||||||
|
Sue 257: goldfish: 3, akitas: 2, perfumes: 6
|
||||||
|
Sue 258: cats: 7, trees: 0, vizslas: 1
|
||||||
|
Sue 259: perfumes: 7, cars: 7, akitas: 7
|
||||||
|
Sue 260: goldfish: 0, vizslas: 0, samoyeds: 2
|
||||||
|
Sue 261: vizslas: 2, children: 2, cats: 3
|
||||||
|
Sue 262: vizslas: 2, pomeranians: 9, samoyeds: 3
|
||||||
|
Sue 263: cats: 1, akitas: 3, vizslas: 1
|
||||||
|
Sue 264: pomeranians: 10, trees: 2, goldfish: 7
|
||||||
|
Sue 265: samoyeds: 5, trees: 7, perfumes: 4
|
||||||
|
Sue 266: perfumes: 10, cars: 1, pomeranians: 3
|
||||||
|
Sue 267: trees: 6, goldfish: 1, cars: 0
|
||||||
|
Sue 268: cars: 6, samoyeds: 4, pomeranians: 5
|
||||||
|
Sue 269: goldfish: 3, vizslas: 3, akitas: 3
|
||||||
|
Sue 270: children: 5, cats: 0, cars: 4
|
||||||
|
Sue 271: goldfish: 3, perfumes: 8, pomeranians: 7
|
||||||
|
Sue 272: samoyeds: 6, cars: 7, perfumes: 10
|
||||||
|
Sue 273: trees: 4, cars: 2, vizslas: 7
|
||||||
|
Sue 274: samoyeds: 10, perfumes: 9, goldfish: 6
|
||||||
|
Sue 275: cars: 4, trees: 2, perfumes: 7
|
||||||
|
Sue 276: akitas: 3, perfumes: 9, cars: 9
|
||||||
|
Sue 277: akitas: 8, vizslas: 2, cats: 6
|
||||||
|
Sue 278: trees: 5, goldfish: 7, akitas: 3
|
||||||
|
Sue 279: perfumes: 9, cars: 8, vizslas: 2
|
||||||
|
Sue 280: trees: 3, vizslas: 0, children: 0
|
||||||
|
Sue 281: cars: 7, trees: 2, cats: 5
|
||||||
|
Sue 282: vizslas: 4, cars: 10, cats: 3
|
||||||
|
Sue 283: akitas: 10, cats: 3, samoyeds: 9
|
||||||
|
Sue 284: trees: 7, children: 5, goldfish: 6
|
||||||
|
Sue 285: cars: 2, perfumes: 5, cats: 7
|
||||||
|
Sue 286: samoyeds: 5, trees: 10, goldfish: 6
|
||||||
|
Sue 287: goldfish: 10, perfumes: 4, trees: 7
|
||||||
|
Sue 288: vizslas: 9, trees: 9, perfumes: 0
|
||||||
|
Sue 289: trees: 4, goldfish: 9, vizslas: 8
|
||||||
|
Sue 290: vizslas: 3, cars: 3, trees: 2
|
||||||
|
Sue 291: goldfish: 2, akitas: 2, trees: 2
|
||||||
|
Sue 292: children: 1, cars: 0, vizslas: 5
|
||||||
|
Sue 293: trees: 5, akitas: 4, goldfish: 6
|
||||||
|
Sue 294: akitas: 3, vizslas: 7, pomeranians: 5
|
||||||
|
Sue 295: goldfish: 10, vizslas: 3, trees: 1
|
||||||
|
Sue 296: cars: 2, trees: 1, akitas: 0
|
||||||
|
Sue 297: akitas: 10, vizslas: 6, samoyeds: 2
|
||||||
|
Sue 298: children: 5, trees: 1, samoyeds: 9
|
||||||
|
Sue 299: perfumes: 9, trees: 6, vizslas: 1
|
||||||
|
Sue 300: akitas: 7, pomeranians: 6, vizslas: 6
|
||||||
|
Sue 301: cats: 7, children: 6, vizslas: 7
|
||||||
|
Sue 302: trees: 2, vizslas: 7, samoyeds: 4
|
||||||
|
Sue 303: goldfish: 0, samoyeds: 10, cars: 4
|
||||||
|
Sue 304: pomeranians: 9, children: 3, vizslas: 5
|
||||||
|
Sue 305: akitas: 8, vizslas: 4, cars: 5
|
||||||
|
Sue 306: akitas: 0, perfumes: 2, pomeranians: 10
|
||||||
|
Sue 307: akitas: 9, cars: 0, trees: 2
|
||||||
|
Sue 308: vizslas: 10, goldfish: 8, akitas: 6
|
||||||
|
Sue 309: trees: 0, cats: 6, perfumes: 2
|
||||||
|
Sue 310: vizslas: 10, cars: 1, trees: 4
|
||||||
|
Sue 311: goldfish: 8, perfumes: 6, cats: 3
|
||||||
|
Sue 312: goldfish: 0, children: 1, akitas: 2
|
||||||
|
Sue 313: pomeranians: 10, trees: 6, samoyeds: 6
|
||||||
|
Sue 314: vizslas: 5, akitas: 4, pomeranians: 2
|
||||||
|
Sue 315: goldfish: 7, trees: 0, akitas: 5
|
||||||
|
Sue 316: goldfish: 4, vizslas: 5, cars: 7
|
||||||
|
Sue 317: perfumes: 7, cats: 10, cars: 4
|
||||||
|
Sue 318: samoyeds: 10, cars: 9, trees: 7
|
||||||
|
Sue 319: pomeranians: 8, vizslas: 6, cars: 3
|
||||||
|
Sue 320: cars: 4, cats: 9, akitas: 4
|
||||||
|
Sue 321: cars: 6, trees: 2, perfumes: 6
|
||||||
|
Sue 322: goldfish: 1, cats: 2, perfumes: 4
|
||||||
|
Sue 323: akitas: 6, cats: 5, cars: 8
|
||||||
|
Sue 324: cats: 4, vizslas: 9, akitas: 0
|
||||||
|
Sue 325: children: 8, samoyeds: 9, trees: 4
|
||||||
|
Sue 326: vizslas: 2, samoyeds: 10, perfumes: 7
|
||||||
|
Sue 327: goldfish: 7, pomeranians: 4, akitas: 10
|
||||||
|
Sue 328: perfumes: 8, cats: 4, akitas: 10
|
||||||
|
Sue 329: trees: 0, cars: 9, goldfish: 3
|
||||||
|
Sue 330: trees: 5, samoyeds: 7, perfumes: 8
|
||||||
|
Sue 331: cars: 4, perfumes: 2, goldfish: 0
|
||||||
|
Sue 332: vizslas: 4, pomeranians: 7, akitas: 1
|
||||||
|
Sue 333: akitas: 4, goldfish: 3, perfumes: 0
|
||||||
|
Sue 334: samoyeds: 3, akitas: 10, vizslas: 0
|
||||||
|
Sue 335: goldfish: 1, akitas: 7, vizslas: 6
|
||||||
|
Sue 336: perfumes: 1, goldfish: 1, pomeranians: 8
|
||||||
|
Sue 337: children: 5, cars: 4, cats: 4
|
||||||
|
Sue 338: vizslas: 5, cars: 10, cats: 3
|
||||||
|
Sue 339: trees: 2, goldfish: 3, cars: 1
|
||||||
|
Sue 340: trees: 10, goldfish: 6, perfumes: 2
|
||||||
|
Sue 341: akitas: 5, trees: 6, cats: 3
|
||||||
|
Sue 342: cars: 10, children: 8, goldfish: 0
|
||||||
|
Sue 343: cats: 2, akitas: 0, pomeranians: 4
|
||||||
|
Sue 344: perfumes: 1, vizslas: 3, cars: 3
|
||||||
|
Sue 345: samoyeds: 8, cats: 5, perfumes: 8
|
||||||
|
Sue 346: cars: 5, akitas: 10, trees: 2
|
||||||
|
Sue 347: vizslas: 9, akitas: 9, cars: 3
|
||||||
|
Sue 348: cars: 3, perfumes: 1, pomeranians: 9
|
||||||
|
Sue 349: akitas: 1, cars: 4, perfumes: 0
|
||||||
|
Sue 350: perfumes: 8, vizslas: 2, trees: 6
|
||||||
|
Sue 351: pomeranians: 5, akitas: 9, cats: 8
|
||||||
|
Sue 352: pomeranians: 8, vizslas: 3, goldfish: 10
|
||||||
|
Sue 353: trees: 2, pomeranians: 0, goldfish: 6
|
||||||
|
Sue 354: cats: 5, akitas: 7, goldfish: 6
|
||||||
|
Sue 355: goldfish: 6, children: 4, trees: 10
|
||||||
|
Sue 356: children: 1, trees: 3, akitas: 7
|
||||||
|
Sue 357: trees: 2, samoyeds: 10, goldfish: 3
|
||||||
|
Sue 358: samoyeds: 10, cats: 0, goldfish: 0
|
||||||
|
Sue 359: perfumes: 3, children: 6, pomeranians: 1
|
||||||
|
Sue 360: cars: 10, pomeranians: 1, samoyeds: 5
|
||||||
|
Sue 361: samoyeds: 9, pomeranians: 7, perfumes: 6
|
||||||
|
Sue 362: goldfish: 6, trees: 8, perfumes: 9
|
||||||
|
Sue 363: samoyeds: 10, pomeranians: 9, children: 10
|
||||||
|
Sue 364: perfumes: 3, goldfish: 7, cars: 9
|
||||||
|
Sue 365: cats: 3, children: 4, samoyeds: 8
|
||||||
|
Sue 366: trees: 0, cars: 10, vizslas: 10
|
||||||
|
Sue 367: pomeranians: 10, children: 8, perfumes: 2
|
||||||
|
Sue 368: cars: 5, vizslas: 0, samoyeds: 3
|
||||||
|
Sue 369: trees: 1, goldfish: 8, cars: 8
|
||||||
|
Sue 370: vizslas: 0, cars: 2, perfumes: 5
|
||||||
|
Sue 371: trees: 2, cars: 3, vizslas: 8
|
||||||
|
Sue 372: trees: 10, children: 9, cats: 1
|
||||||
|
Sue 373: pomeranians: 3, perfumes: 1, vizslas: 0
|
||||||
|
Sue 374: vizslas: 0, perfumes: 6, trees: 0
|
||||||
|
Sue 375: vizslas: 7, pomeranians: 1, akitas: 10
|
||||||
|
Sue 376: vizslas: 8, trees: 2, cars: 10
|
||||||
|
Sue 377: perfumes: 9, cats: 5, goldfish: 5
|
||||||
|
Sue 378: cats: 0, akitas: 10, perfumes: 9
|
||||||
|
Sue 379: cars: 4, akitas: 1, trees: 1
|
||||||
|
Sue 380: cars: 4, perfumes: 5, trees: 3
|
||||||
|
Sue 381: goldfish: 3, akitas: 5, samoyeds: 9
|
||||||
|
Sue 382: goldfish: 7, perfumes: 5, trees: 5
|
||||||
|
Sue 383: akitas: 4, cats: 6, cars: 8
|
||||||
|
Sue 384: children: 6, goldfish: 10, akitas: 7
|
||||||
|
Sue 385: akitas: 7, vizslas: 5, perfumes: 10
|
||||||
|
Sue 386: children: 7, vizslas: 10, akitas: 10
|
||||||
|
Sue 387: goldfish: 6, akitas: 7, trees: 2
|
||||||
|
Sue 388: vizslas: 6, trees: 1, akitas: 2
|
||||||
|
Sue 389: cars: 5, vizslas: 3, akitas: 7
|
||||||
|
Sue 390: vizslas: 4, cats: 8, perfumes: 7
|
||||||
|
Sue 391: akitas: 3, trees: 0, children: 2
|
||||||
|
Sue 392: cats: 7, cars: 3, children: 9
|
||||||
|
Sue 393: trees: 10, vizslas: 3, goldfish: 7
|
||||||
|
Sue 394: perfumes: 0, goldfish: 7, akitas: 4
|
||||||
|
Sue 395: cats: 6, cars: 7, vizslas: 0
|
||||||
|
Sue 396: vizslas: 4, perfumes: 6, goldfish: 5
|
||||||
|
Sue 397: pomeranians: 8, trees: 1, akitas: 9
|
||||||
|
Sue 398: goldfish: 7, pomeranians: 6, samoyeds: 9
|
||||||
|
Sue 399: perfumes: 10, cars: 1, trees: 8
|
||||||
|
Sue 400: trees: 0, goldfish: 9, children: 6
|
||||||
|
Sue 401: trees: 1, cars: 6, pomeranians: 8
|
||||||
|
Sue 402: perfumes: 9, cars: 0, vizslas: 10
|
||||||
|
Sue 403: samoyeds: 4, akitas: 1, vizslas: 9
|
||||||
|
Sue 404: perfumes: 0, trees: 2, cars: 4
|
||||||
|
Sue 405: akitas: 0, perfumes: 5, samoyeds: 4
|
||||||
|
Sue 406: akitas: 8, vizslas: 6, children: 2
|
||||||
|
Sue 407: children: 1, trees: 8, goldfish: 10
|
||||||
|
Sue 408: pomeranians: 4, trees: 10, cars: 9
|
||||||
|
Sue 409: perfumes: 5, vizslas: 5, akitas: 4
|
||||||
|
Sue 410: trees: 1, akitas: 10, vizslas: 6
|
||||||
|
Sue 411: samoyeds: 0, goldfish: 9, perfumes: 7
|
||||||
|
Sue 412: goldfish: 7, samoyeds: 10, trees: 1
|
||||||
|
Sue 413: samoyeds: 0, pomeranians: 10, vizslas: 6
|
||||||
|
Sue 414: children: 2, cars: 10, samoyeds: 2
|
||||||
|
Sue 415: trees: 2, goldfish: 8, cars: 0
|
||||||
|
Sue 416: samoyeds: 4, goldfish: 9, trees: 2
|
||||||
|
Sue 417: trees: 8, akitas: 10, perfumes: 3
|
||||||
|
Sue 418: samoyeds: 9, goldfish: 2, cars: 1
|
||||||
|
Sue 419: akitas: 2, perfumes: 8, trees: 2
|
||||||
|
Sue 420: children: 3, goldfish: 6, perfumes: 5
|
||||||
|
Sue 421: akitas: 8, perfumes: 2, samoyeds: 6
|
||||||
|
Sue 422: vizslas: 10, akitas: 4, pomeranians: 3
|
||||||
|
Sue 423: cats: 8, perfumes: 3, trees: 4
|
||||||
|
Sue 424: cars: 2, children: 4, pomeranians: 8
|
||||||
|
Sue 425: pomeranians: 4, samoyeds: 2, goldfish: 4
|
||||||
|
Sue 426: perfumes: 6, cars: 4, goldfish: 4
|
||||||
|
Sue 427: akitas: 0, goldfish: 7, perfumes: 5
|
||||||
|
Sue 428: perfumes: 4, cars: 3, akitas: 5
|
||||||
|
Sue 429: trees: 0, vizslas: 0, goldfish: 1
|
||||||
|
Sue 430: perfumes: 4, vizslas: 2, cars: 7
|
||||||
|
Sue 431: goldfish: 7, pomeranians: 8, trees: 0
|
||||||
|
Sue 432: goldfish: 7, children: 9, trees: 3
|
||||||
|
Sue 433: akitas: 1, vizslas: 10, trees: 2
|
||||||
|
Sue 434: perfumes: 2, cars: 4, goldfish: 10
|
||||||
|
Sue 435: pomeranians: 6, vizslas: 9, trees: 1
|
||||||
|
Sue 436: cars: 9, trees: 0, goldfish: 0
|
||||||
|
Sue 437: trees: 1, goldfish: 1, vizslas: 8
|
||||||
|
Sue 438: goldfish: 7, samoyeds: 8, children: 2
|
||||||
|
Sue 439: children: 1, cats: 7, vizslas: 8
|
||||||
|
Sue 440: cats: 2, pomeranians: 6, goldfish: 4
|
||||||
|
Sue 441: perfumes: 7, cats: 3, vizslas: 6
|
||||||
|
Sue 442: akitas: 4, samoyeds: 5, cars: 2
|
||||||
|
Sue 443: akitas: 3, perfumes: 3, cats: 9
|
||||||
|
Sue 444: perfumes: 10, akitas: 6, trees: 0
|
||||||
|
Sue 445: cars: 5, children: 9, perfumes: 8
|
||||||
|
Sue 446: vizslas: 10, cars: 3, perfumes: 5
|
||||||
|
Sue 447: children: 9, perfumes: 1, cars: 10
|
||||||
|
Sue 448: akitas: 0, goldfish: 8, trees: 3
|
||||||
|
Sue 449: cars: 7, akitas: 8, children: 3
|
||||||
|
Sue 450: cars: 4, akitas: 9, cats: 0
|
||||||
|
Sue 451: perfumes: 4, samoyeds: 5, goldfish: 6
|
||||||
|
Sue 452: perfumes: 10, akitas: 1, cars: 7
|
||||||
|
Sue 453: trees: 1, goldfish: 3, vizslas: 6
|
||||||
|
Sue 454: goldfish: 8, pomeranians: 6, trees: 10
|
||||||
|
Sue 455: akitas: 5, vizslas: 8, goldfish: 10
|
||||||
|
Sue 456: cats: 5, trees: 4, samoyeds: 0
|
||||||
|
Sue 457: perfumes: 8, cars: 0, cats: 3
|
||||||
|
Sue 458: akitas: 1, trees: 10, vizslas: 2
|
||||||
|
Sue 459: vizslas: 6, akitas: 3, children: 10
|
||||||
|
Sue 460: perfumes: 7, trees: 9, goldfish: 8
|
||||||
|
Sue 461: children: 6, vizslas: 4, perfumes: 5
|
||||||
|
Sue 462: vizslas: 6, akitas: 8, perfumes: 9
|
||||||
|
Sue 463: goldfish: 8, cars: 4, trees: 10
|
||||||
|
Sue 464: pomeranians: 8, cars: 5, vizslas: 0
|
||||||
|
Sue 465: cats: 10, goldfish: 7, akitas: 1
|
||||||
|
Sue 466: cats: 2, children: 1, cars: 6
|
||||||
|
Sue 467: perfumes: 3, samoyeds: 6, cars: 0
|
||||||
|
Sue 468: samoyeds: 10, pomeranians: 6, trees: 2
|
||||||
|
Sue 469: children: 2, perfumes: 2, pomeranians: 4
|
||||||
|
Sue 470: cats: 1, perfumes: 5, vizslas: 9
|
||||||
|
Sue 471: vizslas: 5, perfumes: 2, akitas: 7
|
||||||
|
Sue 472: samoyeds: 8, goldfish: 6, cats: 1
|
||||||
|
Sue 473: goldfish: 10, perfumes: 9, cars: 4
|
||||||
|
Sue 474: samoyeds: 0, cars: 4, vizslas: 4
|
||||||
|
Sue 475: trees: 2, cars: 7, akitas: 8
|
||||||
|
Sue 476: vizslas: 3, perfumes: 5, goldfish: 1
|
||||||
|
Sue 477: cats: 7, cars: 4, trees: 1
|
||||||
|
Sue 478: vizslas: 8, akitas: 3, goldfish: 0
|
||||||
|
Sue 479: cars: 6, cats: 3, perfumes: 2
|
||||||
|
Sue 480: goldfish: 1, children: 9, vizslas: 3
|
||||||
|
Sue 481: pomeranians: 5, vizslas: 1, cars: 10
|
||||||
|
Sue 482: children: 5, perfumes: 5, cats: 1
|
||||||
|
Sue 483: perfumes: 2, goldfish: 7, trees: 6
|
||||||
|
Sue 484: akitas: 2, goldfish: 4, perfumes: 10
|
||||||
|
Sue 485: samoyeds: 3, goldfish: 0, akitas: 1
|
||||||
|
Sue 486: trees: 8, vizslas: 9, goldfish: 0
|
||||||
|
Sue 487: goldfish: 8, samoyeds: 0, trees: 0
|
||||||
|
Sue 488: perfumes: 7, cars: 5, trees: 0
|
||||||
|
Sue 489: vizslas: 3, pomeranians: 2, perfumes: 5
|
||||||
|
Sue 490: cars: 5, perfumes: 5, akitas: 5
|
||||||
|
Sue 491: children: 8, trees: 1, pomeranians: 4
|
||||||
|
Sue 492: pomeranians: 0, akitas: 1, vizslas: 8
|
||||||
|
Sue 493: akitas: 10, perfumes: 10, samoyeds: 8
|
||||||
|
Sue 494: perfumes: 6, vizslas: 4, cats: 6
|
||||||
|
Sue 495: children: 6, pomeranians: 5, samoyeds: 4
|
||||||
|
Sue 496: vizslas: 1, trees: 5, akitas: 1
|
||||||
|
Sue 497: vizslas: 10, perfumes: 10, pomeranians: 3
|
||||||
|
Sue 498: samoyeds: 3, trees: 2, cars: 5
|
||||||
|
Sue 499: cats: 6, children: 3, perfumes: 0
|
||||||
|
Sue 500: pomeranians: 10, cats: 3, vizslas: 5
|
70
2015/day16/main.go
Normal file
70
2015/day16/main.go
Normal file
@ -0,0 +1,70 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bufio"
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
"strconv"
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
|
var req map[string]int
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
var input []string
|
||||||
|
scanner := bufio.NewScanner(os.Stdin)
|
||||||
|
for scanner.Scan() {
|
||||||
|
input = append(input, scanner.Text())
|
||||||
|
}
|
||||||
|
|
||||||
|
req = make(map[string]int)
|
||||||
|
req["children"] = 3
|
||||||
|
req["cats"] = 7
|
||||||
|
req["samoyeds"] = 2
|
||||||
|
req["pomeranians"] = 3
|
||||||
|
req["akitas"] = 0
|
||||||
|
req["vizslas"] = 0
|
||||||
|
req["goldfish"] = 5
|
||||||
|
req["trees"] = 3
|
||||||
|
req["cars"] = 2
|
||||||
|
req["perfumes"] = 1
|
||||||
|
|
||||||
|
for i := range input {
|
||||||
|
if checkString(input[i]) {
|
||||||
|
fmt.Println(input[i])
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func checkString(s string) bool {
|
||||||
|
split := strings.SplitN(s, ": ", 2)
|
||||||
|
items := strings.Split(split[1], ", ")
|
||||||
|
for i := range items {
|
||||||
|
tst := strings.Split(items[i], ": ")
|
||||||
|
if tst[0] == "trees" || tst[0] == "cats" {
|
||||||
|
if req[tst[0]] > mustAtoi(tst[1]) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
} else if tst[0] == "pomeranians" || tst[0] == "goldfish" {
|
||||||
|
if req[tst[0]] < mustAtoi(tst[1]) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if req[tst[0]] != mustAtoi(tst[1]) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
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
|
||||||
|
}
|
98
2015/day16/problem
Normal file
98
2015/day16/problem
Normal file
@ -0,0 +1,98 @@
|
|||||||
|
Advent of Code
|
||||||
|
|
||||||
|
br0xen 40*
|
||||||
|
|
||||||
|
• [About]
|
||||||
|
• [Stats]
|
||||||
|
• [Leaderboard]
|
||||||
|
• [Settings]
|
||||||
|
• [Log out]
|
||||||
|
|
||||||
|
--- Day 16: Aunt Sue ---
|
||||||
|
|
||||||
|
Your Aunt Sue has given you a wonderful gift, and you'd like to send her a thank you card.
|
||||||
|
However, there's a small problem: she signed it "From, Aunt Sue".
|
||||||
|
|
||||||
|
You have 500 Aunts named "Sue".
|
||||||
|
|
||||||
|
So, to avoid sending the card to the wrong person, you need to figure out which Aunt Sue (which
|
||||||
|
you conveniently number 1 to 500, for sanity) gave you the gift. You open the present and, as
|
||||||
|
luck would have it, good ol' Aunt Sue got you a My First Crime Scene Analysis Machine! Just
|
||||||
|
what you wanted. Or needed, as the case may be.
|
||||||
|
|
||||||
|
The My First Crime Scene Analysis Machine (MFCSAM for short) can detect a few specific
|
||||||
|
compounds in a given sample, as well as how many distinct kinds of those compounds there are.
|
||||||
|
According to the instructions, these are what the MFCSAM can detect:
|
||||||
|
|
||||||
|
• children, by human DNA age analysis.
|
||||||
|
• cats. It doesn't differentiate individual breeds.
|
||||||
|
• Several seemingly random breeds of dog: samoyeds, pomeranians, akitas, and vizslas.
|
||||||
|
• goldfish. No other kinds of fish.
|
||||||
|
• trees, all in one group.
|
||||||
|
• cars, presumably by exhaust or gasoline or something.
|
||||||
|
• perfumes, which is handy, since many of your Aunts Sue wear a few kinds.
|
||||||
|
|
||||||
|
In fact, many of your Aunts Sue have many of these. You put the wrapping from the gift into the
|
||||||
|
MFCSAM. It beeps inquisitively at you a few times and then prints out a message on ticker tape:
|
||||||
|
|
||||||
|
children: 3
|
||||||
|
cats: 7
|
||||||
|
samoyeds: 2
|
||||||
|
pomeranians: 3
|
||||||
|
akitas: 0
|
||||||
|
vizslas: 0
|
||||||
|
goldfish: 5
|
||||||
|
trees: 3
|
||||||
|
cars: 2
|
||||||
|
perfumes: 1
|
||||||
|
|
||||||
|
You make a list of the things you can remember about each Aunt Sue. Things missing from your
|
||||||
|
list aren't zero - you simply don't remember the value.
|
||||||
|
|
||||||
|
What is the number of the Sue that got you the gift?
|
||||||
|
|
||||||
|
Your puzzle answer was 373.
|
||||||
|
|
||||||
|
--- Part Two ---
|
||||||
|
|
||||||
|
As you're about to send the thank you note, something in the MFCSAM's instructions catches your
|
||||||
|
eye. Apparently, it has an outdated retroencabulator, and so the output from the machine isn't
|
||||||
|
exact values - some of them indicate ranges.
|
||||||
|
|
||||||
|
In particular, the cats and trees readings indicates that there are greater than that many (due
|
||||||
|
to the unpredictable nuclear decay of cat dander and tree pollen), while the pomeranians and
|
||||||
|
goldfish readings indicate that there are fewer than that many (due to the modial interaction
|
||||||
|
of magnetoreluctance).
|
||||||
|
|
||||||
|
What is the number of the real Aunt Sue?
|
||||||
|
|
||||||
|
Your puzzle answer was 260.
|
||||||
|
|
||||||
|
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
|
||||||
|
. https://en.wikipedia.org/wiki/Samoyed_%28dog%29
|
||||||
|
. https://en.wikipedia.org/wiki/Pomeranian_%28dog%29
|
||||||
|
. https://en.wikipedia.org/wiki/Akita_%28dog%29
|
||||||
|
. https://en.wikipedia.org/wiki/Vizsla
|
||||||
|
. https://en.wikipedia.org/wiki/Ticker_tape
|
||||||
|
. https://www.youtube.com/watch?v=RXJKdh1KZ0w
|
||||||
|
. http://adventofcode.com/
|
||||||
|
. http://adventofcode.com/day/16/input
|
||||||
|
. https://twitter.com/intent/tweet?text=I%27ve+completed+%22Aunt+Sue%22+%2D+Day+16+%2D+Advent+of+Code&url=http%3A%2F%2Fadventofcode%2Ecom%2Fday%2F16&related=ericwastl&hashtags=AdventOfCode
|
||||||
|
. https://plus.google.com/share?url=http%3A%2F%2Fadventofcode%2Ecom%2Fday%2F16
|
||||||
|
. http://www.reddit.com/submit?url=http%3A%2F%2Fadventofcode%2Ecom%2Fday%2F16&title=I%27ve+completed+%22Aunt+Sue%22+%2D+Day+16+%2D+Advent+of+Code
|
20
2015/day17/input
Normal file
20
2015/day17/input
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
33
|
||||||
|
14
|
||||||
|
18
|
||||||
|
20
|
||||||
|
45
|
||||||
|
35
|
||||||
|
16
|
||||||
|
35
|
||||||
|
1
|
||||||
|
13
|
||||||
|
18
|
||||||
|
13
|
||||||
|
50
|
||||||
|
44
|
||||||
|
48
|
||||||
|
6
|
||||||
|
24
|
||||||
|
41
|
||||||
|
30
|
||||||
|
42
|
151
2015/day17/main.go
Normal file
151
2015/day17/main.go
Normal file
@ -0,0 +1,151 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bufio"
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
"strconv"
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
|
type container struct {
|
||||||
|
value int
|
||||||
|
name string
|
||||||
|
}
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
if len(os.Args) < 2 {
|
||||||
|
fmt.Println("Usage: day17 <liters>")
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
total := mustAtoi(os.Args[1])
|
||||||
|
|
||||||
|
var input []string
|
||||||
|
scanner := bufio.NewScanner(os.Stdin)
|
||||||
|
for scanner.Scan() {
|
||||||
|
input = append(input, scanner.Text())
|
||||||
|
}
|
||||||
|
|
||||||
|
var containers []container
|
||||||
|
for i := range input {
|
||||||
|
val := mustAtoi(input[i])
|
||||||
|
// Generate a name for this container
|
||||||
|
var u int
|
||||||
|
for j := range containers {
|
||||||
|
if containers[j].value == val {
|
||||||
|
u++
|
||||||
|
}
|
||||||
|
}
|
||||||
|
n := strconv.Itoa(val) + "-" + strconv.Itoa(u)
|
||||||
|
containers = append(containers, container{value: val, name: n})
|
||||||
|
}
|
||||||
|
fmt.Println("All Containers: ")
|
||||||
|
fmt.Println(containers)
|
||||||
|
fmt.Println()
|
||||||
|
|
||||||
|
fmt.Println("Finding Combinations...")
|
||||||
|
res := findCombis(total, containers)
|
||||||
|
var final [][]container
|
||||||
|
fmt.Println()
|
||||||
|
fmt.Println("Sorting Results...")
|
||||||
|
for i := 0; i < len(res); i++ {
|
||||||
|
tst := sortContainers(res[i])
|
||||||
|
var dup bool
|
||||||
|
for j := 0; j < len(final); j++ {
|
||||||
|
if isEqual(tst, final[j]) {
|
||||||
|
dup = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if !dup {
|
||||||
|
final = append(final, tst)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
minNum := len(final[0])
|
||||||
|
var minConfig [][]container
|
||||||
|
for i := 0; i < len(final); i++ {
|
||||||
|
if len(final[i]) < minNum {
|
||||||
|
minNum = len(final[i])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for i := 0; i < len(final); i++ {
|
||||||
|
if len(final[i]) == minNum {
|
||||||
|
minConfig = append(minConfig, final[i])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fmt.Print("Total Combinations: ")
|
||||||
|
fmt.Println(strconv.Itoa(len(final)))
|
||||||
|
|
||||||
|
fmt.Println("Minimum Containers: " + strconv.Itoa(minNum))
|
||||||
|
fmt.Println("Num Configurations: " + strconv.Itoa(len(minConfig)))
|
||||||
|
}
|
||||||
|
|
||||||
|
func findCombis(total int, containers []container) [][]container {
|
||||||
|
var ret [][]container
|
||||||
|
|
||||||
|
for i := range containers {
|
||||||
|
if total == containers[i].value {
|
||||||
|
fmt.Print("O")
|
||||||
|
ret = append(ret, []container{containers[i]})
|
||||||
|
}
|
||||||
|
if containers[i].value < total {
|
||||||
|
fmt.Print(".")
|
||||||
|
bld := []container{containers[i]}
|
||||||
|
|
||||||
|
var pass []container
|
||||||
|
for j := range containers {
|
||||||
|
if i != j {
|
||||||
|
pass = append(pass, containers[j])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
tmp := findCombis((total - containers[i].value), pass)
|
||||||
|
|
||||||
|
for idx := 0; idx < len(tmp); idx++ {
|
||||||
|
tmp[idx] = append(bld, tmp[idx]...)
|
||||||
|
}
|
||||||
|
ret = append(ret, tmp...)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ret
|
||||||
|
}
|
||||||
|
|
||||||
|
func sortContainers(c []container) []container {
|
||||||
|
n := len(c)
|
||||||
|
swapped := true
|
||||||
|
for swapped {
|
||||||
|
swapped = false
|
||||||
|
for i := 1; i <= n-1; i++ {
|
||||||
|
if strings.Compare(c[i-1].name, c[i].name) > 0 {
|
||||||
|
tmp := c[i-1]
|
||||||
|
c[i-1] = c[i]
|
||||||
|
c[i] = tmp
|
||||||
|
swapped = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
n = n - 1
|
||||||
|
}
|
||||||
|
return c
|
||||||
|
}
|
||||||
|
|
||||||
|
func isEqual(a, b []container) bool {
|
||||||
|
if len(a) != len(b) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
for i := 0; i < len(a); i++ {
|
||||||
|
if a[i].name != b[i].name {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
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
|
||||||
|
}
|
64
2015/day17/problem
Normal file
64
2015/day17/problem
Normal file
@ -0,0 +1,64 @@
|
|||||||
|
Advent of Code
|
||||||
|
|
||||||
|
br0xen 40*
|
||||||
|
|
||||||
|
• [About]
|
||||||
|
• [Stats]
|
||||||
|
• [Leaderboard]
|
||||||
|
• [Settings]
|
||||||
|
• [Log out]
|
||||||
|
|
||||||
|
--- Day 17: No Such Thing as Too Much ---
|
||||||
|
|
||||||
|
The elves bought too much eggnog again - 150 liters this time. To fit it all into your
|
||||||
|
refrigerator, you'll need to move it into smaller containers. You take an inventory of the
|
||||||
|
capacities of the available containers.
|
||||||
|
|
||||||
|
For example, suppose you have containers of size 20, 15, 10, 5, and 5 liters. If you need to
|
||||||
|
store 25 liters, there are four ways to do it:
|
||||||
|
|
||||||
|
• 15 and 10
|
||||||
|
• 20 and 5 (the first 5)
|
||||||
|
• 20 and 5 (the second 5)
|
||||||
|
• 15, 5, and 5
|
||||||
|
|
||||||
|
Filling all containers entirely, how many different combinations of containers can exactly fit
|
||||||
|
all 150 liters of eggnog?
|
||||||
|
|
||||||
|
Your puzzle answer was 1304.
|
||||||
|
|
||||||
|
--- Part Two ---
|
||||||
|
|
||||||
|
While playing with all the containers in the kitchen, another load of eggnog arrives! The
|
||||||
|
shipping and receiving department is requesting as many containers as you can spare.
|
||||||
|
|
||||||
|
Find the minimum number of containers that can exactly fit all 150 liters of eggnog. How many
|
||||||
|
different ways can you fill that number of containers and still hold exactly 150 litres?
|
||||||
|
|
||||||
|
In the example above, the minimum number of containers was two. There were three ways to use
|
||||||
|
that many containers, and so the answer there would be 3.
|
||||||
|
|
||||||
|
Your puzzle answer was 18.
|
||||||
|
|
||||||
|
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/17/input
|
||||||
|
. https://twitter.com/intent/tweet?text=I%27ve+completed+%22No+Such+Thing+as+Too+Much%22+%2D+Day+17+%2D+Advent+of+Code&url=http%3A%2F%2Fadventofcode%2Ecom%2Fday%2F17&related=ericwastl&hashtags=AdventOfCode
|
||||||
|
. https://plus.google.com/share?url=http%3A%2F%2Fadventofcode%2Ecom%2Fday%2F17
|
||||||
|
. http://www.reddit.com/submit?url=http%3A%2F%2Fadventofcode%2Ecom%2Fday%2F17&title=I%27ve+completed+%22No+Such+Thing+as+Too+Much%22+%2D+Day+17+%2D+Advent+of+Code
|
5
2015/day17/sample_input
Normal file
5
2015/day17/sample_input
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
20
|
||||||
|
15
|
||||||
|
10
|
||||||
|
5
|
||||||
|
5
|
BIN
2015/day18/day18.gif
Normal file
BIN
2015/day18/day18.gif
Normal file
Binary file not shown.
After Width: | Height: | Size: 541 KiB |
100
2015/day18/input
Normal file
100
2015/day18/input
Normal file
@ -0,0 +1,100 @@
|
|||||||
|
#...##......#......##.##..#...##......##.#.#.###.#.#..#..#......####..#......###.#.#....#..##..###..
|
||||||
|
####..#.#...#....#.#####.##.##.#..#.......#....#.##...###.###..#.#.#........#..#.#.##...##..#.####.#
|
||||||
|
...#..##...#.#.###.#.###..#.##.####.###...#...........#.###..##.#.##.#.###...#.#..###....#.###.#..#.
|
||||||
|
.#...##...####.#..#.....#..#...#.#.##...#...##..#.#.###....#..###.....##..#.###..###.....##..###...#
|
||||||
|
..##.#####....##..#.#..##.##..######...#..###.######.....#..##...#.#..##..##..#..#..#..##.#.#.#.#...
|
||||||
|
.###.###.###...##...##..###..##.###.#.....##..##.#.#########...##..##.#..##.#..##..####..#.#.#.#####
|
||||||
|
#.#####..###.###.##.##.#...#.#.#.#..#.###...#..##.###.#...####.#..#.#.....###..#..####..#.#.#...##..
|
||||||
|
....#...##.....#....####.##.#.###..#.#.##..#.#...##.###.###..#.##..#.#.##..##..#.##.###..#.#.###.###
|
||||||
|
##.##...#.##...#.#..#.#..#...###...###.#..#..#.#####..###.#......#.....###.#####.#.#..#.#.#.##..#.#.
|
||||||
|
#.#..#.....#.....##.#..##...###..##...##...###.#.###.#..#.#.###...##..##..#.###...#.#######.#...#.#.
|
||||||
|
#.#.....####.#..#.##...#.##....#####.###.#.....#####....###..#........##..####...#...#.###....#..###
|
||||||
|
##.#.##..#.#.##.#.....##.#.....###.####.#..######.....####.#.#..##.#.##...#..#.#.....#.####.#.......
|
||||||
|
#..#..#.#..#.######.##..##.####.....##.#.##.#.######..#.#....#.#...#.#..#..#.#.###.#..#.#.#..#...###
|
||||||
|
####..####.#.#.###.....#.#.#.##..#.##.##.##.#..##..##.#.##.....#.#..#.####.....###.#..#.####.#.#..##
|
||||||
|
###.##..##.#.##..#..##...#.#####.##.#....##.####.#.##....#..###.#.#.##...#.....#.#.#.#.#..##.#.#..#.
|
||||||
|
......#..####...##.##...#.##.##...##..#..##.###..#...#..##...#.#....###.####...#.##.###.#.##.####.##
|
||||||
|
..#...#####.#.#..#.##....#..#...#..####.....###...##.###....#..#.###...#........#.#.##..#..#.#.....#
|
||||||
|
#######.#.#.###.###..######.##..#####.##.###.###....####.#..##.##...###.#..############.#.##....##.#
|
||||||
|
#.#...##.###.#.###..#.#.#.#.#.#..##..####.#..##.....#.##..#.##...##.#..##..#.#.#....##....##.#..#.#.
|
||||||
|
..#.#.####.....###..#######.#.#.#.#...##.#####.....##...##...##.###..######.###..#...####.#..###.###
|
||||||
|
.#.##....#.#.##..##.#.##.##..######...#.....#..#.#.#.#.....#.#..##.#.#.......#######....#.......#...
|
||||||
|
..###.##.##..##....#.###...#.....##..##......###...##..###.##...##.###.#.#.#.###.###.#.#...###..#...
|
||||||
|
.##.#.#...#...##.#.#...#..#..#.#...##.#.##...##..#....#.#..##.#..#.#..#.#.....#..#.#...#######.#.##.
|
||||||
|
...####....#.###.#..###..##...##..#.#.#.###...#..##.##.##..##.#...#..#.##.....#.#........#..#.#.####
|
||||||
|
.....##..###...#....#.#.#.#...###.###...#.#...#.#.####....#..####...###..#..######..##.##..###.#####
|
||||||
|
#####.##..#....###.###....##.....#.#..#....#.#####.##.#.####.#.##...#..###...###..##...#.###.#####..
|
||||||
|
###.##..........########.######....####.###.#..##...#.##.####.#.....##..#####..###...#####.....#.#.#
|
||||||
|
##..#####.##.#.#####.#.##.##..#.##....########.#####.#...#.###.##...#.###.#.#..#....##.#..#...#.#.#.
|
||||||
|
.##.#....#..#...#..#####..#..##.#......#..#....########...#..#...#.....####.#...##...#.###.#.#..##.#
|
||||||
|
.##.##.#.##.#.##...#.#.#..##.##.###.#..##..#...###.##.###.#####.#.###..#..###.#...#.###.#...#..#.#.#
|
||||||
|
.#..#..#.#..#..###..#....###.####.##.#.###.#.##.###.#.##.###.###...###...###.#...####...#.##.##.#.#.
|
||||||
|
###..##...###...#..##.#..#.#...##....###.##.##..#####....###..#..#....#..###.###.#...#.##...#.#.#..#
|
||||||
|
#....#.......##.....#.##...#..#.###.#.##..##..#.##..#.###..##.##...#####.#..#####..#####..#####....#
|
||||||
|
.####.####....###..###.#.##.####.##.#...####.#.###.#.....#...####..#####.###..#.#.###.##.##...##..#.
|
||||||
|
####..##...##.########...##..###..#..###.##.#.#.#........#.#####.#...#.###.####.#..####..#.#.#....##
|
||||||
|
###.#..#...###.#..#..#.###...##..###.##.#.#...#..#...####..##....#.#..#..##.#.#...#####.###.#..#.#.#
|
||||||
|
...##....#.###.#.#..##...##.###.#..#..#......#...#.#..####.#.##..######.####.#...#..#..#..##.#.#.##.
|
||||||
|
##.####.#...#..#.#.##..##.#.#.###..##...####......#..######.#......#.##.#....##...###.#.#..#......##
|
||||||
|
#.....#...#######.##.#..#.#...###.#..#.####....#.#.##.#.##...###..#...#.###.##..#.###..#.##...#####.
|
||||||
|
#####.##...#..#.#.#.......#.##..#####..#####...###..##.#.#..###.#.#####.####..#.#..##...#.##...#.###
|
||||||
|
.##.#..#######.###.#.####.....##...#.##.#.#..#...##....####......######.#..######.....##########.##.
|
||||||
|
##...#.#..#.##.###.#.#.#.##.###.##..##.##.##...#.#..###.#######..#.....#####..#....######.#..##..###
|
||||||
|
.#.#.###.....#..##..#.#..##..#.###...###.#..##...#...#.#####.#.#####..###.#..#...##..#.#..#..####...
|
||||||
|
.#......##..#.....####.###....##.###.....###.##........#.###.##..#..#.#######.#.######..##..###.....
|
||||||
|
..##.#.#..#.##...#.###.###...######..#..#.#..#....###.#.#....#..........#...##.##.##.#..##..#.#####.
|
||||||
|
###.###.#..#.##..##.#..#..##.....##.....#..#######.#..#.#.#.####.###..###.#.#..#.##.##.####.###.####
|
||||||
|
#.#.#..#....########.#..#..#...##..#.##..#.#..##..####...##.....#.##.#.#...########..#.###.#..#.#.##
|
||||||
|
.##.....#...#.#...##.##....###...##..#.####...#..#.#..#..#.##..#.###.##.####.##..####.....##.#.....#
|
||||||
|
....####.#.##.#.##.#..##.#.######.##.####..#...####.#..###.#.#..#..##.#.#.....##.#####.#.####...#.#.
|
||||||
|
#..#####.#####.....##....######..##....#..#.#.###.#####.....##.##.####.#...##...#.##.#.#####.##.#...
|
||||||
|
##.####..###.#....#...#.#.#.#.###.#####.#.####..####...####......##..#..#..#.#.##...########....#...
|
||||||
|
.###.#.#.#.#..####.##.#..######..#.#.###.....#.#......#.#.#.#..####.##...##.#####.#.##..##..#..#.#..
|
||||||
|
.....###...#...#.####.###.#.#.#.#.....#....#.####.###.##.##.##.#######......#.####......#....##.....
|
||||||
|
##..#..#.#.##..#...#..##.##.##..###.#....##.##....####.#.##.###....#.##.#.#.##...##.###...#..#..####
|
||||||
|
...#.#..##..##.#...##.##...#.#......#.#.##..###....####.##...#.#.###.#..#..#.####..##..##..#####.###
|
||||||
|
.##.##..##########.##...#.##.####.#.#######.##.#.##.##..#...##....########.###..##.##.##.#..##.#.#.#
|
||||||
|
#####.#....#.##..#.....#......##.##..#.##.###..##.......###..##.#.###.##.###....####.#..#.###..#.#.#
|
||||||
|
.#...#..#.##....##....#...####....#...#..#...####...########.###.#..##.#.#.##..###..#.#.###.....##.#
|
||||||
|
##..##.....###......#..###.##.####.##.####.#.#....#..#...#..#.#..#.###.#...#...#..##.##...#..#######
|
||||||
|
.....##..###..##...#####.#.#.....###.#.#..####...#.#.#..#..####..##.#..###.####.#....##..###....#..#
|
||||||
|
#.#.##.#....#.#####.#....##...#...##...##....#.#.......#....#..#...###.###.#.####..####....#.##.#.#.
|
||||||
|
..##...##..###.#.#.##.#..#....#.#.....##.###.#.###.###.....#...#.#..#######.#####..#.###...##......#
|
||||||
|
#......###..#....#.#..#.###.##.#...##..###.####.#.#....#.##..#.###..##.#..#####..##.###.....#..###..
|
||||||
|
##.#.##..##.###.#..##.....#.##.....###....##.####.######.#...#..###....#.#...#.##.....###....#..#.#.
|
||||||
|
.##.#.#.#.##..#.#.#..##..#.###.####....#..###.######..####.#.....###.##..#...###.#..######.##.#.##..
|
||||||
|
...##.####.#..##.#####.##.#...##..#..#...#.#.#.#####...#....#..###...#..#....#.#.##.#.######.#..####
|
||||||
|
..#.#.#.#...#.######.#.....#..#.#..###....#.#.########...#....#.#.##..#...##...#.#..#.#.###....##...
|
||||||
|
#####..#..##..#..##..#..#.#.##.#....#####.####.##.#.###..##..##....#.....#.#####.#...#.#####.##.#.#.
|
||||||
|
#.#..#####...####.###.###.....####.###.....##...##...#..#..#######.#.##....##..####.....##...#..#..#
|
||||||
|
#.#.###.#.#..##..#....#.#...#.#.##.##..#.##.....##...#.#..##.......##.#.###..#####.#.##....#.##.....
|
||||||
|
...#.......#....#.#.####.#.###.###..#....#..##.#..####........#.##..#...#.#...###.#..#.#.#...#...#..
|
||||||
|
...##.#####.##.#.###.##.##.#.##..##.#.#.#.#.#.##.#..##...##.#.#..#..##.##.#####.#.###...#####..#..#.
|
||||||
|
#######.#..#..#....##.#.#..####.#..#..###...#..#.......###.#.#.####....#.###...#.#.###.#.#.#.#..###.
|
||||||
|
..##.##.#.##.###....###.##.#.###.#...#....#.####..###..###.#.#..#...##.#.#.#..##.###..###.#.##...###
|
||||||
|
######..######..##..##.#.#.##.##.#..##..#.#.#.##..#.#...#...#.#.#..######.#..#.#.######..#......##.#
|
||||||
|
#.#####.....#.......#########..###.##...#...##.#.#..#...#####...#...#..#.###.#..#.#...###.#.#.#...#.
|
||||||
|
#....##....###...##.##.#...##.........##.#.#..#.#.##.#.######.#####..#..###.###.#...#.#.##.######...
|
||||||
|
#.#...###.#.###.##.#.######.#######.###.##..#.#.#...######.##.####.##..#.#.#.#......##..##.........#
|
||||||
|
..###..##....#.....##...#.#.###.#.#.....##.#...###.####.#...#...##..##.#.#.####..###...######....#.#
|
||||||
|
..###.#.##.####.#..#.##....##..#####....#..##.##.#..#######...#.####...##.#.#.##.........#....#....#
|
||||||
|
.##.#...#.####..#.#...#.##..######.##..##.#.###.##..###.###....##..#.##.##..##.#...###.##.##.###....
|
||||||
|
#...###.###.#..#....#.......#..#.....###..#.###.##.##....#.####.#.####.##..##..#..#.....#....##.#.#.
|
||||||
|
.##.#..#..#.##.......#.####.#######.....#.##.##.#.....#.#..#....######.#..###.##.##.....#.####..##.#
|
||||||
|
###..#.###.#..####.....##....#..####....#.##.##..#...######.#########...#.#....##...###.#..#.##...#.
|
||||||
|
#..###..##..#.#.##.###.#.#.##...###.#...##.##..#.###....###..#.#...#.###..######.#..#.###..#..#..#.#
|
||||||
|
.#........##.#.###..###.#.#.##.....##.##.#.#...##..#.##....###..#.#.#.#.##....#.##..#.#...###...#...
|
||||||
|
####.####..#....#.#.#..#..##.......##.####...###.##..#.#.##.#..##..######.......##.#.##..#...#.....#
|
||||||
|
..#..#..###..##.##..######.#..###..###.#.##..##.#..#####.#.#.#.##..#.##..##.##......####.#..........
|
||||||
|
...##.##..###.#...###....#.#.#.#.....#.##.....##...#...#......####...##.##....##.#..#.####.#..###.#.
|
||||||
|
..#.....####.#.###.#####..#..###..#..#.#...#####...###.###....#.###..#...#..#..#.#..#.##..##.#.#....
|
||||||
|
..##.#####...###.###.........#....##.####.##..#.#..#.#...#...##.##.##..#.#.##.########......#####...
|
||||||
|
...###.#.#..#...#.###.###.......##.###.#..#.##########...#..#.#.#.##.#.###...######..#.#...###.##...
|
||||||
|
.#.#.#######.#..##.##..##...#...####...#..#####.#..##...###.#.#...#.##...#......#..##.####..#.....##
|
||||||
|
.##.##.#.#......#######..###.....##.#.##..###......#....####...#.###.#.##.#........#..#....##.....##
|
||||||
|
#...#.###.#.##...##.####....#...#.###..#.#.....#.#....#.#.#.##...#.#..#####.#.#..#..#..#....#...####
|
||||||
|
.....##...###......#####..##.##.##...##.#.#####..##...#.#.#.#.###...###.##.####..#.#..#.#..#.####.##
|
||||||
|
#..#..##.#.##.#.##.#.#.#..###....###.##.#.##.#...#.#..#...#....###.#..#.#.######.#...####..#..##.#.#
|
||||||
|
#..#.#..#...###.#..##.#...#...##.#......#...#..#..####..##.....#.###...#.#..#.#....#.#####.##.###...
|
||||||
|
###....#.#..#.#..###..#.##......#...#..#..##.#..###..##..#..#.####..#...########..##.#.##.#.#.#...#.
|
||||||
|
.#.#.##.##.###..#...#.#....#..#.##..#.#.#.#.##.##.#####...#........####..###..####.#####..#.##.#.##.
|
211
2015/day18/main.go
Normal file
211
2015/day18/main.go
Normal file
@ -0,0 +1,211 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bufio"
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
"os/exec"
|
||||||
|
"strconv"
|
||||||
|
"strings"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
var lights [][]bool
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
ticks := -1
|
||||||
|
speed := 2
|
||||||
|
var hideSim, lockedCorners bool
|
||||||
|
for i := range os.Args {
|
||||||
|
if os.Args[i] == "-help" {
|
||||||
|
fmt.Println("Usage: day18 [-ticks=<num>] [-speed=<num>]")
|
||||||
|
fmt.Println("\t-ticks=<num>\tSpecify how many iterations should be performed")
|
||||||
|
fmt.Println("\t\t\t\tIf not manually set, run forever.")
|
||||||
|
fmt.Println("\t-speed=<num>\tSpecify how many times/second we iterate")
|
||||||
|
fmt.Println("\t-hide\t\tHide the actual simulation (for AoC)")
|
||||||
|
fmt.Println("\t-lockcorners\t\tLock the corner lights 'on' (for AoC pt 2)")
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
if j := strings.Index(os.Args[i], "="); j > 0 {
|
||||||
|
flagKey := os.Args[i][:j]
|
||||||
|
flagVal := os.Args[i][j+1:]
|
||||||
|
if flagKey == "-ticks" {
|
||||||
|
ticks = mustAtoi(flagVal)
|
||||||
|
} else if flagKey == "-speed" {
|
||||||
|
speed = mustAtoi(flagVal)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if os.Args[i] == "-hide" {
|
||||||
|
hideSim = true
|
||||||
|
}
|
||||||
|
if os.Args[i] == "-lockcorners" {
|
||||||
|
lockedCorners = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if hideSim && ticks == -1 {
|
||||||
|
// Doesn't make sense to run this configuration
|
||||||
|
fmt.Println("You asked to run indefinitely and hide the simulation...")
|
||||||
|
fmt.Println("Refusing to needlessly consume your CPU.")
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
|
||||||
|
var input []string
|
||||||
|
scanner := bufio.NewScanner(os.Stdin)
|
||||||
|
for scanner.Scan() {
|
||||||
|
input = append(input, scanner.Text())
|
||||||
|
}
|
||||||
|
|
||||||
|
for i := range input {
|
||||||
|
var bldRow []bool
|
||||||
|
for j := range input[i] {
|
||||||
|
bldRow = append(bldRow, (input[i][j] == '#'))
|
||||||
|
}
|
||||||
|
lights = append(lights, bldRow)
|
||||||
|
}
|
||||||
|
|
||||||
|
if !hideSim {
|
||||||
|
cls()
|
||||||
|
printLights(lights)
|
||||||
|
}
|
||||||
|
for i := 0; i < ticks || ticks == -1; i++ {
|
||||||
|
if lockedCorners {
|
||||||
|
lights = lockCorners(lights)
|
||||||
|
}
|
||||||
|
lights = tick(lights)
|
||||||
|
if lockedCorners {
|
||||||
|
lights = lockCorners(lights)
|
||||||
|
}
|
||||||
|
if !hideSim {
|
||||||
|
cls()
|
||||||
|
printLights(lights)
|
||||||
|
}
|
||||||
|
if !hideSim {
|
||||||
|
// No reason to sleep if we're hiding the simulation
|
||||||
|
time.Sleep(time.Second / time.Duration(speed))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fmt.Println("After " + strconv.Itoa(ticks) + " ticks, " + strconv.Itoa(countLights(lights)) + " are on")
|
||||||
|
}
|
||||||
|
|
||||||
|
func lockCorners(c [][]bool) [][]bool {
|
||||||
|
c[0][0] = true
|
||||||
|
c[0][len(c[0])-1] = true
|
||||||
|
c[len(c)-1][0] = true
|
||||||
|
c[len(c)-1][len(c[0])-1] = true
|
||||||
|
return c
|
||||||
|
}
|
||||||
|
|
||||||
|
func cls() {
|
||||||
|
cmd := exec.Command("clear")
|
||||||
|
cmd.Stdout = os.Stdout
|
||||||
|
cmd.Run()
|
||||||
|
}
|
||||||
|
|
||||||
|
func printLights(curr [][]bool) {
|
||||||
|
for i := range curr {
|
||||||
|
for j := range curr {
|
||||||
|
if curr[i][j] {
|
||||||
|
fmt.Print("#")
|
||||||
|
} else {
|
||||||
|
fmt.Print(".")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
fmt.Println()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func tick(curr [][]bool) [][]bool {
|
||||||
|
var next [][]bool
|
||||||
|
for i := range curr {
|
||||||
|
var bldRow []bool
|
||||||
|
for j := range curr[i] {
|
||||||
|
num := checkNeighbors(curr, i, j)
|
||||||
|
var newVal bool
|
||||||
|
if curr[i][j] {
|
||||||
|
// On proc
|
||||||
|
if num == 2 || num == 3 {
|
||||||
|
newVal = true
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// Off proc
|
||||||
|
if num == 3 {
|
||||||
|
newVal = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
bldRow = append(bldRow, newVal)
|
||||||
|
}
|
||||||
|
next = append(next, bldRow)
|
||||||
|
}
|
||||||
|
return next
|
||||||
|
}
|
||||||
|
|
||||||
|
// Returns how many neighbors are on
|
||||||
|
func checkNeighbors(curr [][]bool, i, j int) int {
|
||||||
|
var ret int
|
||||||
|
// nw
|
||||||
|
if isOn(curr, (i - 1), (j - 1)) {
|
||||||
|
ret++
|
||||||
|
}
|
||||||
|
// n
|
||||||
|
if isOn(curr, (i - 1), j) {
|
||||||
|
ret++
|
||||||
|
}
|
||||||
|
// ne
|
||||||
|
if isOn(curr, (i - 1), (j + 1)) {
|
||||||
|
ret++
|
||||||
|
}
|
||||||
|
// w
|
||||||
|
if isOn(curr, i, (j - 1)) {
|
||||||
|
ret++
|
||||||
|
}
|
||||||
|
// e
|
||||||
|
if isOn(curr, i, (j + 1)) {
|
||||||
|
ret++
|
||||||
|
}
|
||||||
|
// sw
|
||||||
|
if isOn(curr, (i + 1), (j - 1)) {
|
||||||
|
ret++
|
||||||
|
}
|
||||||
|
// s
|
||||||
|
if isOn(curr, (i + 1), j) {
|
||||||
|
ret++
|
||||||
|
}
|
||||||
|
// se
|
||||||
|
if isOn(curr, (i + 1), (j + 1)) {
|
||||||
|
ret++
|
||||||
|
}
|
||||||
|
return ret
|
||||||
|
}
|
||||||
|
|
||||||
|
func isOn(curr [][]bool, i, j int) bool {
|
||||||
|
if i < 0 || i >= len(curr) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
if j < 0 || j >= len(curr[i]) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
return curr[i][j]
|
||||||
|
}
|
||||||
|
|
||||||
|
func countLights(c [][]bool) int {
|
||||||
|
var ttl int
|
||||||
|
for i := range c {
|
||||||
|
for j := range c[i] {
|
||||||
|
if c[i][j] {
|
||||||
|
ttl++
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ttl
|
||||||
|
}
|
||||||
|
|
||||||
|
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
|
||||||
|
}
|
180
2015/day18/problem
Normal file
180
2015/day18/problem
Normal file
@ -0,0 +1,180 @@
|
|||||||
|
Advent of Code
|
||||||
|
|
||||||
|
br0xen 40*
|
||||||
|
|
||||||
|
• [About]
|
||||||
|
• [Stats]
|
||||||
|
• [Leaderboard]
|
||||||
|
• [Settings]
|
||||||
|
• [Log out]
|
||||||
|
|
||||||
|
--- Day 18: Like a GIF For Your Yard ---
|
||||||
|
|
||||||
|
After the million lights incident, the fire code has gotten stricter: now, at most ten thousand
|
||||||
|
lights are allowed. You arrange them in a 100x100 grid.
|
||||||
|
|
||||||
|
Never one to let you down, Santa again mails you instructions on the ideal lighting
|
||||||
|
configuration. With so few lights, he says, you'll have to resort to animation.
|
||||||
|
|
||||||
|
Start by setting your lights to the included initial configuration (your puzzle input). A #
|
||||||
|
means "on", and a . means "off".
|
||||||
|
|
||||||
|
Then, animate your grid in steps, where each step decides the next configuration based on the
|
||||||
|
current one. Each light's next state (either on or off) depends on its current state and the
|
||||||
|
current states of the eight lights adjacent to it (including diagonals). Lights on the edge of
|
||||||
|
the grid might have fewer than eight neighbors; the missing ones always count as "off".
|
||||||
|
|
||||||
|
For example, in a simplified 6x6 grid, the light marked A has the neighbors numbered 1 through
|
||||||
|
8, and the light marked B, which is on an edge, only has the neighbors marked 1 through 5:
|
||||||
|
|
||||||
|
1B5...
|
||||||
|
234...
|
||||||
|
......
|
||||||
|
..123.
|
||||||
|
..8A4.
|
||||||
|
..765.
|
||||||
|
|
||||||
|
The state a light should have next is based on its current state (on or off) plus the number of
|
||||||
|
neighbors that are on:
|
||||||
|
|
||||||
|
• A light which is on stays on when 2 or 3 neighbors are on, and turns off otherwise.
|
||||||
|
• A light which is off turns on if exactly 3 neighbors are on, and stays off otherwise.
|
||||||
|
|
||||||
|
All of the lights update simultaneously; they all consider the same current state before moving
|
||||||
|
to the next.
|
||||||
|
|
||||||
|
Here's a few steps from an example configuration of another 6x6 grid:
|
||||||
|
|
||||||
|
Initial state:
|
||||||
|
.#.#.#
|
||||||
|
...##.
|
||||||
|
#....#
|
||||||
|
..#...
|
||||||
|
#.#..#
|
||||||
|
####..
|
||||||
|
|
||||||
|
After 1 step:
|
||||||
|
..##..
|
||||||
|
..##.#
|
||||||
|
...##.
|
||||||
|
......
|
||||||
|
#.....
|
||||||
|
#.##..
|
||||||
|
|
||||||
|
After 2 steps:
|
||||||
|
..###.
|
||||||
|
......
|
||||||
|
..###.
|
||||||
|
......
|
||||||
|
.#....
|
||||||
|
.#....
|
||||||
|
|
||||||
|
After 3 steps:
|
||||||
|
...#..
|
||||||
|
......
|
||||||
|
...#..
|
||||||
|
..##..
|
||||||
|
......
|
||||||
|
......
|
||||||
|
|
||||||
|
After 4 steps:
|
||||||
|
......
|
||||||
|
......
|
||||||
|
..##..
|
||||||
|
..##..
|
||||||
|
......
|
||||||
|
......
|
||||||
|
|
||||||
|
After 4 steps, this example has four lights on.
|
||||||
|
|
||||||
|
In your grid of 100x100 lights, given your initial configuration, how many lights are on after
|
||||||
|
100 steps?
|
||||||
|
|
||||||
|
Your puzzle answer was 814.
|
||||||
|
|
||||||
|
--- Part Two ---
|
||||||
|
|
||||||
|
You flip the instructions over; Santa goes on to point out that this is all just an
|
||||||
|
implementation of Conway's Game of Life. At least, it was, until you notice that something's
|
||||||
|
wrong with the grid of lights you bought: four lights, one in each corner, are stuck on and
|
||||||
|
can't be turned off. The example above will actually run like this:
|
||||||
|
|
||||||
|
Initial state:
|
||||||
|
##.#.#
|
||||||
|
...##.
|
||||||
|
#....#
|
||||||
|
..#...
|
||||||
|
#.#..#
|
||||||
|
####.#
|
||||||
|
|
||||||
|
After 1 step:
|
||||||
|
#.##.#
|
||||||
|
####.#
|
||||||
|
...##.
|
||||||
|
......
|
||||||
|
#...#.
|
||||||
|
#.####
|
||||||
|
|
||||||
|
After 2 steps:
|
||||||
|
#..#.#
|
||||||
|
#....#
|
||||||
|
.#.##.
|
||||||
|
...##.
|
||||||
|
.#..##
|
||||||
|
##.###
|
||||||
|
|
||||||
|
After 3 steps:
|
||||||
|
#...##
|
||||||
|
####.#
|
||||||
|
..##.#
|
||||||
|
......
|
||||||
|
##....
|
||||||
|
####.#
|
||||||
|
|
||||||
|
After 4 steps:
|
||||||
|
#.####
|
||||||
|
#....#
|
||||||
|
...#..
|
||||||
|
.##...
|
||||||
|
#.....
|
||||||
|
#.#..#
|
||||||
|
|
||||||
|
After 5 steps:
|
||||||
|
##.###
|
||||||
|
.##..#
|
||||||
|
.##...
|
||||||
|
.##...
|
||||||
|
#.#...
|
||||||
|
##...#
|
||||||
|
|
||||||
|
After 5 steps, this example now has 17 lights on.
|
||||||
|
|
||||||
|
In your grid of 100x100 lights, given your initial configuration, but with the four corners
|
||||||
|
always in the on state, how many lights are on after 100 steps?
|
||||||
|
|
||||||
|
Your puzzle answer was 924.
|
||||||
|
|
||||||
|
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/day/6
|
||||||
|
. https://en.wikipedia.org/wiki/Conway's_Game_of_Life
|
||||||
|
. http://adventofcode.com/
|
||||||
|
. http://adventofcode.com/day/18/input
|
||||||
|
. https://twitter.com/intent/tweet?text=I%27ve+completed+%22Like+a+GIF+For+Your+Yard%22+%2D+Day+18+%2D+Advent+of+Code&url=http%3A%2F%2Fadventofcode%2Ecom%2Fday%2F18&related=ericwastl&hashtags=AdventOfCode
|
||||||
|
. https://plus.google.com/share?url=http%3A%2F%2Fadventofcode%2Ecom%2Fday%2F18
|
||||||
|
. http://www.reddit.com/submit?url=http%3A%2F%2Fadventofcode%2Ecom%2Fday%2F18&title=I%27ve+completed+%22Like+a+GIF+For+Your+Yard%22+%2D+Day+18+%2D+Advent+of+Code
|
6
2015/day18/sample_input
Normal file
6
2015/day18/sample_input
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
.#.#.#
|
||||||
|
...##.
|
||||||
|
#....#
|
||||||
|
..#...
|
||||||
|
#.#..#
|
||||||
|
####..
|
45
2015/day19/input
Normal file
45
2015/day19/input
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
Al => ThF
|
||||||
|
Al => ThRnFAr
|
||||||
|
B => BCa
|
||||||
|
B => TiB
|
||||||
|
B => TiRnFAr
|
||||||
|
Ca => CaCa
|
||||||
|
Ca => PB
|
||||||
|
Ca => PRnFAr
|
||||||
|
Ca => SiRnFYFAr
|
||||||
|
Ca => SiRnMgAr
|
||||||
|
Ca => SiTh
|
||||||
|
F => CaF
|
||||||
|
F => PMg
|
||||||
|
F => SiAl
|
||||||
|
H => CRnAlAr
|
||||||
|
H => CRnFYFYFAr
|
||||||
|
H => CRnFYMgAr
|
||||||
|
H => CRnMgYFAr
|
||||||
|
H => HCa
|
||||||
|
H => NRnFYFAr
|
||||||
|
H => NRnMgAr
|
||||||
|
H => NTh
|
||||||
|
H => OB
|
||||||
|
H => ORnFAr
|
||||||
|
Mg => BF
|
||||||
|
Mg => TiMg
|
||||||
|
N => CRnFAr
|
||||||
|
N => HSi
|
||||||
|
O => CRnFYFAr
|
||||||
|
O => CRnMgAr
|
||||||
|
O => HP
|
||||||
|
O => NRnFAr
|
||||||
|
O => OTi
|
||||||
|
P => CaP
|
||||||
|
P => PTi
|
||||||
|
P => SiRnFAr
|
||||||
|
Si => CaSi
|
||||||
|
Th => ThCa
|
||||||
|
Ti => BP
|
||||||
|
Ti => TiTi
|
||||||
|
e => HF
|
||||||
|
e => NAl
|
||||||
|
e => OMg
|
||||||
|
|
||||||
|
CRnSiRnCaPTiMgYCaPTiRnFArSiThFArCaSiThSiThPBCaCaSiRnSiRnTiTiMgArPBCaPMgYPTiRnFArFArCaSiRnBPMgArPRnCaPTiRnFArCaSiThCaCaFArPBCaCaPTiTiRnFArCaSiRnSiAlYSiThRnFArArCaSiRnBFArCaCaSiRnSiThCaCaCaFYCaPTiBCaSiThCaSiThPMgArSiRnCaPBFYCaCaFArCaCaCaCaSiThCaSiRnPRnFArPBSiThPRnFArSiRnMgArCaFYFArCaSiRnSiAlArTiTiTiTiTiTiTiRnPMgArPTiTiTiBSiRnSiAlArTiTiRnPMgArCaFYBPBPTiRnSiRnMgArSiThCaFArCaSiThFArPRnFArCaSiRnTiBSiThSiRnSiAlYCaFArPRnFArSiThCaFArCaCaSiThCaCaCaSiRnPRnCaFArFYPMgArCaPBCaPBSiRnFYPBCaFArCaSiAl
|
123
2015/day19/main.go
Normal file
123
2015/day19/main.go
Normal file
@ -0,0 +1,123 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bufio"
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
"strconv"
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
var input []string
|
||||||
|
scanner := bufio.NewScanner(os.Stdin)
|
||||||
|
for scanner.Scan() {
|
||||||
|
input = append(input, scanner.Text())
|
||||||
|
}
|
||||||
|
|
||||||
|
transforms := make(map[string][]string)
|
||||||
|
var stMolecule string
|
||||||
|
|
||||||
|
for i := range input {
|
||||||
|
if strings.Contains(input[i], "=>") {
|
||||||
|
parts := strings.Split(input[i], " => ")
|
||||||
|
transforms[parts[0]] = append(transforms[parts[0]], parts[1])
|
||||||
|
} else if len(input[i]) > 0 {
|
||||||
|
// Must be the calibration molecule
|
||||||
|
stMolecule = input[i]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fmt.Println("*** CALIBRATION ***")
|
||||||
|
res := calibrate(stMolecule, transforms)
|
||||||
|
fmt.Println("Found " + strconv.Itoa(len(res)) + " combinations")
|
||||||
|
fmt.Println("\n")
|
||||||
|
fmt.Println("*** MANUFACTURING ***")
|
||||||
|
backTrans := reverseTransforms(transforms)
|
||||||
|
manufacture(stMolecule, backTrans, 0)
|
||||||
|
}
|
||||||
|
|
||||||
|
// stepBack takes an ending string and a reversed list of the transformations
|
||||||
|
func manufacture(molecule string, transforms map[string][]string, steps int) {
|
||||||
|
fmt.Println(molecule)
|
||||||
|
|
||||||
|
if molecule == "e" {
|
||||||
|
fmt.Println("Found in " + strconv.Itoa(steps) + " steps")
|
||||||
|
os.Exit(0)
|
||||||
|
}
|
||||||
|
|
||||||
|
for k, v := range transforms {
|
||||||
|
if strings.Contains(molecule, k) {
|
||||||
|
for i := range v {
|
||||||
|
tstVal := strings.Replace(molecule, k, v[i], 1)
|
||||||
|
manufacture(tstVal, transforms, steps+1)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func reverseTransforms(t map[string][]string) map[string][]string {
|
||||||
|
ret := make(map[string][]string)
|
||||||
|
for v := range t {
|
||||||
|
for j := range t[v] {
|
||||||
|
ret[t[v][j]] = append(ret[t[v][j]], v)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ret
|
||||||
|
}
|
||||||
|
|
||||||
|
func calibrate(molecule string, transforms map[string][]string) []string {
|
||||||
|
var ret []string
|
||||||
|
atoms := getAtomsFromMolecule(molecule)
|
||||||
|
|
||||||
|
for i := range atoms {
|
||||||
|
// Build a string of atoms before i
|
||||||
|
start := strings.Join(atoms[:i], "")
|
||||||
|
// And all after i too
|
||||||
|
end := strings.Join(atoms[i+1:], "")
|
||||||
|
// Find all transforms for atoms[i]
|
||||||
|
if v, ok := transforms[atoms[i]]; ok {
|
||||||
|
for j := range v {
|
||||||
|
ret = uniqueInsert(ret, start+v[j]+end)
|
||||||
|
//ret = append(ret, start+v[j]+end)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ret
|
||||||
|
}
|
||||||
|
|
||||||
|
func getAtomsFromMolecule(molecule string) []string {
|
||||||
|
var atoms []string
|
||||||
|
var bldAtom string
|
||||||
|
|
||||||
|
for i := range molecule {
|
||||||
|
if molecule[i] >= 'A' && molecule[i] <= 'Z' {
|
||||||
|
if len(bldAtom) > 0 {
|
||||||
|
atoms = append(atoms, bldAtom)
|
||||||
|
}
|
||||||
|
bldAtom = string(molecule[i])
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
bldAtom = bldAtom + string(molecule[i])
|
||||||
|
}
|
||||||
|
return append(atoms, bldAtom)
|
||||||
|
}
|
||||||
|
|
||||||
|
func uniqueInsert(curr []string, ins string) []string {
|
||||||
|
for i := range curr {
|
||||||
|
if curr[i] == ins {
|
||||||
|
return curr
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return append(curr, ins)
|
||||||
|
}
|
||||||
|
|
||||||
|
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
|
||||||
|
}
|
107
2015/day19/problem
Normal file
107
2015/day19/problem
Normal file
@ -0,0 +1,107 @@
|
|||||||
|
Advent of Code
|
||||||
|
|
||||||
|
br0xen 40*
|
||||||
|
|
||||||
|
• [About]
|
||||||
|
• [Stats]
|
||||||
|
• [Leaderboard]
|
||||||
|
• [Settings]
|
||||||
|
• [Log out]
|
||||||
|
|
||||||
|
--- Day 19: Medicine for Rudolph ---
|
||||||
|
|
||||||
|
Rudolph the Red-Nosed Reindeer is sick! His nose isn't shining very brightly, and he needs
|
||||||
|
medicine.
|
||||||
|
|
||||||
|
Red-Nosed Reindeer biology isn't similar to regular reindeer biology; Rudolph is going to need
|
||||||
|
custom-made medicine. Unfortunately, Red-Nosed Reindeer chemistry isn't similar to regular
|
||||||
|
reindeer chemistry, either.
|
||||||
|
|
||||||
|
The North Pole is equipped with a Red-Nosed Reindeer nuclear fusion/fission plant, capable of
|
||||||
|
constructing any Red-Nosed Reindeer molecule you need. It works by starting with some input
|
||||||
|
molecule and then doing a series of replacements, one per step, until it has the right
|
||||||
|
molecule.
|
||||||
|
|
||||||
|
However, the machine has to be calibrated before it can be used. Calibration involves
|
||||||
|
determining the number of molecules that can be generated in one step from a given starting
|
||||||
|
point.
|
||||||
|
|
||||||
|
For example, imagine a simpler machine that supports only the following replacements:
|
||||||
|
|
||||||
|
H => HO
|
||||||
|
H => OH
|
||||||
|
O => HH
|
||||||
|
|
||||||
|
Given the replacements above and starting with HOH, the following molecules could be generated:
|
||||||
|
|
||||||
|
• HOOH (via H => HO on the first H).
|
||||||
|
• HOHO (via H => HO on the second H).
|
||||||
|
• OHOH (via H => OH on the first H).
|
||||||
|
• HOOH (via H => OH on the second H).
|
||||||
|
• HHHH (via O => HH).
|
||||||
|
|
||||||
|
So, in the example above, there are 4 distinct molecules (not five, because HOOH appears twice)
|
||||||
|
after one replacement from HOH. Santa's favorite molecule, HOHOHO, can become 7 distinct
|
||||||
|
molecules (over nine replacements: six from H, and three from O).
|
||||||
|
|
||||||
|
The machine replaces without regard for the surrounding characters. For example, given the
|
||||||
|
string H2O, the transition H => OO would result in OO2O.
|
||||||
|
|
||||||
|
Your puzzle input describes all of the possible replacements and, at the bottom, the medicine
|
||||||
|
molecule for which you need to calibrate the machine. How many distinct molecules can be
|
||||||
|
created after all the different ways you can do one replacement on the medicine molecule?
|
||||||
|
|
||||||
|
Your puzzle answer was 518.
|
||||||
|
|
||||||
|
--- Part Two ---
|
||||||
|
|
||||||
|
Now that the machine is calibrated, you're ready to begin molecule fabrication.
|
||||||
|
|
||||||
|
Molecule fabrication always begins with just a single electron, e, and applying replacements
|
||||||
|
one at a time, just like the ones during calibration.
|
||||||
|
|
||||||
|
For example, suppose you have the following replacements:
|
||||||
|
|
||||||
|
e => H
|
||||||
|
e => O
|
||||||
|
H => HO
|
||||||
|
H => OH
|
||||||
|
O => HH
|
||||||
|
|
||||||
|
If you'd like to make HOH, you start with e, and then make the following replacements:
|
||||||
|
|
||||||
|
• e => O to get O
|
||||||
|
• O => HH to get HH
|
||||||
|
• H => OH (on the second H) to get HOH
|
||||||
|
|
||||||
|
So, you could make HOH after 3 steps. Santa's favorite molecule, HOHOHO, can be made in 6
|
||||||
|
steps.
|
||||||
|
|
||||||
|
How long will it take to make the medicine? Given the available replacements and the medicine
|
||||||
|
molecule in your puzzle input, what is the fewest number of steps to go from e to the medicine
|
||||||
|
molecule?
|
||||||
|
|
||||||
|
Your puzzle answer was 200.
|
||||||
|
|
||||||
|
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/19/input
|
||||||
|
. https://twitter.com/intent/tweet?text=I%27ve+completed+%22Medicine+for+Rudolph%22+%2D+Day+19+%2D+Advent+of+Code&url=http%3A%2F%2Fadventofcode%2Ecom%2Fday%2F19&related=ericwastl&hashtags=AdventOfCode
|
||||||
|
. https://plus.google.com/share?url=http%3A%2F%2Fadventofcode%2Ecom%2Fday%2F19
|
||||||
|
. http://www.reddit.com/submit?url=http%3A%2F%2Fadventofcode%2Ecom%2Fday%2F19&title=I%27ve+completed+%22Medicine+for+Rudolph%22+%2D+Day+19+%2D+Advent+of+Code
|
5
2015/day19/sample_input
Normal file
5
2015/day19/sample_input
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
H => HO
|
||||||
|
H => OH
|
||||||
|
O => HH
|
||||||
|
|
||||||
|
HOH
|
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
|
221
2015/day21/main.go
Normal file
221
2015/day21/main.go
Normal file
@ -0,0 +1,221 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
"strconv"
|
||||||
|
)
|
||||||
|
|
||||||
|
var enemyHp int
|
||||||
|
var enemyDmg int
|
||||||
|
var enemyDef int
|
||||||
|
|
||||||
|
var weaponsAvailable []weapon
|
||||||
|
var armorAvailable []armor
|
||||||
|
var ringsAvailable []ring
|
||||||
|
|
||||||
|
var currWeapon, cheapWeapon, highWeapon weapon
|
||||||
|
var currArmor, cheapArmor, highArmor armor
|
||||||
|
var currRing1, cheapRing1, highRing1 ring
|
||||||
|
var currRing2, cheapRing2, highRing2 ring
|
||||||
|
|
||||||
|
// My input: ./day21 100 8 2
|
||||||
|
func main() {
|
||||||
|
if len(os.Args) < 4 || os.Args[1] == "-help" {
|
||||||
|
fmt.Println("Usage: day21 <enemy hp> <enemy dmg> <enemy def")
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
|
||||||
|
enemyHp = mustAtoi(os.Args[1])
|
||||||
|
enemyDmg = mustAtoi(os.Args[2])
|
||||||
|
enemyDef = mustAtoi(os.Args[3])
|
||||||
|
|
||||||
|
cheapest := -1
|
||||||
|
highest := -1
|
||||||
|
initShop()
|
||||||
|
|
||||||
|
for wi := range weaponsAvailable {
|
||||||
|
currWeapon = weaponsAvailable[wi]
|
||||||
|
for ai := range armorAvailable {
|
||||||
|
currArmor = armorAvailable[ai]
|
||||||
|
for r1i := range ringsAvailable {
|
||||||
|
currRing1 = ringsAvailable[r1i]
|
||||||
|
for r2i := range ringsAvailable {
|
||||||
|
if r2i == r1i {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
currRing2 = ringsAvailable[r2i]
|
||||||
|
if toTheDeath(false) {
|
||||||
|
if calcCost() < cheapest || cheapest == -1 {
|
||||||
|
cheapest = calcCost()
|
||||||
|
saveCheapest()
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if calcCost() > highest || highest == -1 {
|
||||||
|
highest = calcCost()
|
||||||
|
saveHighest()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if cheapest >= 0 {
|
||||||
|
fmt.Println("Cheapest Victory: " + itoa(cheapest))
|
||||||
|
fmt.Println("Weapon: " + cheapWeapon.name)
|
||||||
|
fmt.Println("Armor: " + cheapArmor.name)
|
||||||
|
fmt.Println("Ring1: " + cheapRing1.name)
|
||||||
|
fmt.Println("Ring2: " + cheapRing2.name)
|
||||||
|
loadCheapest()
|
||||||
|
toTheDeath(true)
|
||||||
|
} else {
|
||||||
|
fmt.Println("No victory to be had.")
|
||||||
|
}
|
||||||
|
fmt.Println()
|
||||||
|
if highest >= 0 {
|
||||||
|
fmt.Println("Most Expensive Loss: " + itoa(highest))
|
||||||
|
fmt.Println("Weapon: " + highWeapon.name)
|
||||||
|
fmt.Println("Armor: " + highArmor.name)
|
||||||
|
fmt.Println("Ring1: " + highRing1.name)
|
||||||
|
fmt.Println("Ring2: " + highRing2.name)
|
||||||
|
loadHighest()
|
||||||
|
toTheDeath(true)
|
||||||
|
} else {
|
||||||
|
fmt.Println("No victory to be had.")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func loadCheapest() {
|
||||||
|
currWeapon = cheapWeapon
|
||||||
|
currArmor = cheapArmor
|
||||||
|
currRing1 = cheapRing1
|
||||||
|
currRing2 = cheapRing2
|
||||||
|
}
|
||||||
|
|
||||||
|
func saveCheapest() {
|
||||||
|
cheapWeapon = currWeapon
|
||||||
|
cheapArmor = currArmor
|
||||||
|
cheapRing1 = currRing1
|
||||||
|
cheapRing2 = currRing2
|
||||||
|
}
|
||||||
|
|
||||||
|
func loadHighest() {
|
||||||
|
currWeapon = highWeapon
|
||||||
|
currArmor = highArmor
|
||||||
|
currRing1 = highRing1
|
||||||
|
currRing2 = highRing2
|
||||||
|
}
|
||||||
|
|
||||||
|
func saveHighest() {
|
||||||
|
highWeapon = currWeapon
|
||||||
|
highArmor = currArmor
|
||||||
|
highRing1 = currRing1
|
||||||
|
highRing2 = currRing2
|
||||||
|
}
|
||||||
|
|
||||||
|
func toTheDeath(output bool) bool {
|
||||||
|
var pHp, pDmg, pDef, eHp, eDmg, eDef int
|
||||||
|
pHp = 100
|
||||||
|
|
||||||
|
pDmg += currWeapon.damage
|
||||||
|
pDmg += currRing1.damage
|
||||||
|
pDmg += currRing2.damage
|
||||||
|
pDef += currArmor.defense
|
||||||
|
pDef += currRing1.defense
|
||||||
|
pDef += currRing2.defense
|
||||||
|
|
||||||
|
eHp = enemyHp
|
||||||
|
eDmg = enemyDmg
|
||||||
|
eDef = enemyDef
|
||||||
|
|
||||||
|
for pHp > 0 && eHp > 0 {
|
||||||
|
pAtk := pDmg - eDef
|
||||||
|
if pAtk <= 1 {
|
||||||
|
pAtk = 1
|
||||||
|
}
|
||||||
|
eHp -= pAtk
|
||||||
|
eAtk := 1
|
||||||
|
if eHp > 0 {
|
||||||
|
eAtk = eDmg - pDef
|
||||||
|
if eAtk <= 1 {
|
||||||
|
eAtk = 1
|
||||||
|
}
|
||||||
|
pHp -= eAtk
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if output {
|
||||||
|
fmt.Print(itoa(calcCost()) + ": ")
|
||||||
|
fmt.Print(itoa(pHp) + " to " + itoa(eHp) + " ")
|
||||||
|
fmt.Println("DMG(" + itoa(pDmg) + ") DEF(" + itoa(pDef) + ") ")
|
||||||
|
}
|
||||||
|
return pHp > 0
|
||||||
|
}
|
||||||
|
|
||||||
|
func calcCost() int {
|
||||||
|
return currWeapon.cost + currArmor.cost + currRing1.cost + currRing2.cost
|
||||||
|
}
|
||||||
|
|
||||||
|
func initShop() {
|
||||||
|
addWeapon("Dagger", 8, 4)
|
||||||
|
addWeapon("Shortsword", 10, 5)
|
||||||
|
addWeapon("Warhammer", 25, 6)
|
||||||
|
addWeapon("Longsword", 40, 7)
|
||||||
|
addWeapon("Greataxe", 74, 8)
|
||||||
|
|
||||||
|
addArmor("Leather", 13, 1)
|
||||||
|
addArmor("Chainmail", 31, 2)
|
||||||
|
addArmor("Splintmail", 53, 3)
|
||||||
|
addArmor("Bandedmail", 75, 4)
|
||||||
|
addArmor("Platemail", 102, 5)
|
||||||
|
addArmor("No Armor", 0, 0)
|
||||||
|
|
||||||
|
addRing("Damage +1", 25, 1, 0)
|
||||||
|
addRing("Damage +2", 50, 2, 0)
|
||||||
|
addRing("Damage +3", 100, 3, 0)
|
||||||
|
addRing("Defense +1", 20, 0, 1)
|
||||||
|
addRing("Defense +2", 40, 0, 2)
|
||||||
|
addRing("Defense +3", 80, 0, 3)
|
||||||
|
addRing("No Ring 1", 0, 0, 0)
|
||||||
|
addRing("No Ring 2", 0, 0, 0)
|
||||||
|
}
|
||||||
|
func addWeapon(n string, c, dmg int) {
|
||||||
|
weaponsAvailable = append(weaponsAvailable,
|
||||||
|
weapon{name: n, cost: c, damage: dmg})
|
||||||
|
}
|
||||||
|
func addArmor(n string, c, def int) {
|
||||||
|
armorAvailable = append(armorAvailable,
|
||||||
|
armor{name: n, cost: c, defense: def})
|
||||||
|
}
|
||||||
|
func addRing(n string, c, dmg, def int) {
|
||||||
|
ringsAvailable = append(ringsAvailable,
|
||||||
|
ring{name: n, cost: c, damage: dmg, defense: def})
|
||||||
|
}
|
||||||
|
|
||||||
|
type weapon struct {
|
||||||
|
name string
|
||||||
|
cost, damage int
|
||||||
|
}
|
||||||
|
|
||||||
|
type armor struct {
|
||||||
|
name string
|
||||||
|
cost, defense int
|
||||||
|
}
|
||||||
|
|
||||||
|
type ring struct {
|
||||||
|
name string
|
||||||
|
cost, damage, defense int
|
||||||
|
}
|
||||||
|
|
||||||
|
func itoa(i int) string {
|
||||||
|
return strconv.Itoa(i)
|
||||||
|
}
|
||||||
|
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
|
||||||
|
}
|
108
2015/day21/problem
Normal file
108
2015/day21/problem
Normal file
@ -0,0 +1,108 @@
|
|||||||
|
Advent of Code
|
||||||
|
|
||||||
|
br0xen 42*
|
||||||
|
|
||||||
|
• [About]
|
||||||
|
• [Stats]
|
||||||
|
• [Leaderboard]
|
||||||
|
• [Settings]
|
||||||
|
• [Log out]
|
||||||
|
|
||||||
|
--- Day 21: RPG Simulator 20XX ---
|
||||||
|
|
||||||
|
Little Henry Case got a new video game for Christmas. It's an RPG, and he's stuck on a boss.
|
||||||
|
He needs to know what equipment to buy at the shop. He hands you the controller.
|
||||||
|
|
||||||
|
In this game, the player (you) and the enemy (the boss) take turns attacking. The player
|
||||||
|
always goes first. Each attack reduces the opponent's hit points by at least 1. The first
|
||||||
|
character at or below 0 hit points loses.
|
||||||
|
|
||||||
|
Damage dealt by an attacker each turn is equal to the attacker's damage score minus the
|
||||||
|
defender's armor score. An attacker always does at least 1 damage. So, if the attacker has a
|
||||||
|
damage score of 8, and the defender has an armor score of 3, the defender loses 5 hit points.
|
||||||
|
If the defender had an armor score of 300, the defender would still lose 1 hit point.
|
||||||
|
|
||||||
|
Your damage score and armor score both start at zero. They can be increased by buying items in
|
||||||
|
exchange for gold. You start with no items and have as much gold as you need. Your total
|
||||||
|
damage or armor is equal to the sum of those stats from all of your items. You have 100 hit
|
||||||
|
points.
|
||||||
|
|
||||||
|
Here is what the item shop is selling:
|
||||||
|
|
||||||
|
Weapons: Cost Damage Armor
|
||||||
|
Dagger 8 4 0
|
||||||
|
Shortsword 10 5 0
|
||||||
|
Warhammer 25 6 0
|
||||||
|
Longsword 40 7 0
|
||||||
|
Greataxe 74 8 0
|
||||||
|
|
||||||
|
Armor: Cost Damage Armor
|
||||||
|
Leather 13 0 1
|
||||||
|
Chainmail 31 0 2
|
||||||
|
Splintmail 53 0 3
|
||||||
|
Bandedmail 75 0 4
|
||||||
|
Platemail 102 0 5
|
||||||
|
|
||||||
|
Rings: Cost Damage Armor
|
||||||
|
Damage +1 25 1 0
|
||||||
|
Damage +2 50 2 0
|
||||||
|
Damage +3 100 3 0
|
||||||
|
Defense +1 20 0 1
|
||||||
|
Defense +2 40 0 2
|
||||||
|
Defense +3 80 0 3
|
||||||
|
|
||||||
|
You must buy exactly one weapon; no dual-wielding. Armor is optional, but you can't use more
|
||||||
|
than one. You can buy 0-2 rings (at most one for each hand). You must use any items you buy.
|
||||||
|
The shop only has one of each item, so you can't buy, for example, two rings of Damage +3.
|
||||||
|
|
||||||
|
For example, suppose you have 8 hit points, 5 damage, and 5 armor, and that the boss has 12
|
||||||
|
hit points, 7 damage, and 2 armor:
|
||||||
|
|
||||||
|
• The player deals 5-2 = 3 damage; the boss goes down to 9 hit points.
|
||||||
|
• The boss deals 7-5 = 2 damage; the player goes down to 6 hit points.
|
||||||
|
• The player deals 5-2 = 3 damage; the boss goes down to 6 hit points.
|
||||||
|
• The boss deals 7-5 = 2 damage; the player goes down to 4 hit points.
|
||||||
|
• The player deals 5-2 = 3 damage; the boss goes down to 3 hit points.
|
||||||
|
• The boss deals 7-5 = 2 damage; the player goes down to 2 hit points.
|
||||||
|
• The player deals 5-2 = 3 damage; the boss goes down to 0 hit points.
|
||||||
|
|
||||||
|
In this scenario, the player wins! (Barely.)
|
||||||
|
|
||||||
|
You have 100 hit points. The boss's actual stats are in your puzzle input. What is the least
|
||||||
|
amount of gold you can spend and still win the fight?
|
||||||
|
|
||||||
|
Your puzzle answer was 91.
|
||||||
|
|
||||||
|
--- Part Two ---
|
||||||
|
|
||||||
|
Turns out the shopkeeper is working with the boss, and can persuade you to buy whatever items
|
||||||
|
he wants. The other rules still apply, and he still only has one of each item.
|
||||||
|
|
||||||
|
What is the most amount of gold you can spend and still lose the fight?
|
||||||
|
|
||||||
|
Your puzzle answer was 158.
|
||||||
|
|
||||||
|
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
|
||||||
|
. https://en.wikipedia.org/wiki/Role-playing_video_game
|
||||||
|
. https://en.wikipedia.org/wiki/Game_controller
|
||||||
|
. http://adventofcode.com/
|
||||||
|
. http://adventofcode.com/day/21/input
|
||||||
|
. https://twitter.com/intent/tweet?text=I%27ve+completed+%22RPG+Simulator+20XX%22+%2D+Day+21+%2D+Advent+of+Code&url=http%3A%2F%2Fadventofcode%2Ecom%2Fday%2F21&related=ericwastl&hashtags=AdventOfCode
|
||||||
|
. https://plus.google.com/share?url=http%3A%2F%2Fadventofcode%2Ecom%2Fday%2F21
|
||||||
|
. http://www.reddit.com/submit?url=http%3A%2F%2Fadventofcode%2Ecom%2Fday%2F21&title=I%27ve+completed+%22RPG+Simulator+20XX%22+%2D+Day+21+%2D+Advent+of+Code
|
227
2015/day22/main.go
Normal file
227
2015/day22/main.go
Normal file
@ -0,0 +1,227 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
"strconv"
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
playerTurn = iota
|
||||||
|
bossTurn
|
||||||
|
)
|
||||||
|
|
||||||
|
type state struct {
|
||||||
|
bossHp int
|
||||||
|
bossDmg int
|
||||||
|
playerHp int
|
||||||
|
playerMp int
|
||||||
|
playerDef int
|
||||||
|
shield int
|
||||||
|
poison int
|
||||||
|
recharge int
|
||||||
|
manaSpent int
|
||||||
|
move int
|
||||||
|
}
|
||||||
|
|
||||||
|
type spell struct {
|
||||||
|
name string
|
||||||
|
mpCost int
|
||||||
|
damage int
|
||||||
|
heal int
|
||||||
|
duration int
|
||||||
|
}
|
||||||
|
|
||||||
|
var minMp int
|
||||||
|
var spellBook []spell
|
||||||
|
var stateStack []state
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
minMp = -1
|
||||||
|
initSpellBook()
|
||||||
|
if len(os.Args) == 2 && os.Args[1] == "-help" {
|
||||||
|
fmt.Println("Usage: day22 [<boss hp> <boss dmg> [<player hp> <player mp>]]")
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
//debugMode = true
|
||||||
|
eHp := 71
|
||||||
|
eDmg := 10
|
||||||
|
if len(os.Args) >= 3 {
|
||||||
|
eHp = mustAtoi(os.Args[1])
|
||||||
|
eDmg = mustAtoi(os.Args[2])
|
||||||
|
}
|
||||||
|
pHp := 50
|
||||||
|
pMp := 500
|
||||||
|
if len(os.Args) == 5 {
|
||||||
|
pHp = mustAtoi(os.Args[3])
|
||||||
|
pMp = mustAtoi(os.Args[4])
|
||||||
|
}
|
||||||
|
s := state{
|
||||||
|
bossHp: eHp,
|
||||||
|
bossDmg: eDmg,
|
||||||
|
playerHp: pHp,
|
||||||
|
playerMp: pMp,
|
||||||
|
playerDef: 0,
|
||||||
|
shield: 0,
|
||||||
|
poison: 0,
|
||||||
|
recharge: 0,
|
||||||
|
manaSpent: 0,
|
||||||
|
move: playerTurn,
|
||||||
|
}
|
||||||
|
stateStack = append(stateStack, s)
|
||||||
|
for len(stateStack) > 0 {
|
||||||
|
var wrk state
|
||||||
|
wrk, stateStack = stateStack[0], stateStack[1:]
|
||||||
|
// Hard Mode
|
||||||
|
if wrk.move == playerTurn {
|
||||||
|
wrk.playerHp--
|
||||||
|
}
|
||||||
|
wrk.playerDef = 0
|
||||||
|
if wrk.shield > 0 {
|
||||||
|
wrk.playerDef = 7
|
||||||
|
}
|
||||||
|
if wrk.poison > 0 {
|
||||||
|
wrk.bossHp -= 3
|
||||||
|
}
|
||||||
|
if wrk.recharge > 0 {
|
||||||
|
wrk.playerMp += 101
|
||||||
|
}
|
||||||
|
wrk = decrementTimers(wrk)
|
||||||
|
if wrk.playerHp <= 0 || (wrk.manaSpent > minMp && minMp != -1) {
|
||||||
|
// Unsuccessful path
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if wrk.bossHp <= 0 {
|
||||||
|
// Successful path!
|
||||||
|
if minMp == -1 || minMp > wrk.manaSpent {
|
||||||
|
minMp = wrk.manaSpent
|
||||||
|
}
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if wrk.move == bossTurn {
|
||||||
|
wrk.move = playerTurn
|
||||||
|
atk := 1
|
||||||
|
if wrk.bossDmg-wrk.playerDef > 1 {
|
||||||
|
atk = wrk.bossDmg - wrk.playerDef
|
||||||
|
}
|
||||||
|
wrk.playerHp -= atk
|
||||||
|
stateStack = append([]state{wrk}, stateStack...)
|
||||||
|
} else {
|
||||||
|
wrk.move = bossTurn
|
||||||
|
for i := range spellBook {
|
||||||
|
tstSpell := spellBook[i]
|
||||||
|
if tstSpell.mpCost >= wrk.playerMp {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
nextState, ok := castSpell(wrk, tstSpell)
|
||||||
|
if ok {
|
||||||
|
stateStack = append([]state{nextState}, stateStack...)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
fmt.Printf("%d\n", minMp)
|
||||||
|
}
|
||||||
|
|
||||||
|
func castSpell(w state, s spell) (state, bool) {
|
||||||
|
if s.name == "Magic Missile" || s.name == "Drain" {
|
||||||
|
w.bossHp -= s.damage
|
||||||
|
w.playerHp += s.heal
|
||||||
|
} else if s.name == "Shield" {
|
||||||
|
if w.shield > 0 {
|
||||||
|
return w, false
|
||||||
|
}
|
||||||
|
w.shield = s.duration
|
||||||
|
} else if s.name == "Poison" {
|
||||||
|
if w.poison > 0 {
|
||||||
|
return w, false
|
||||||
|
}
|
||||||
|
w.poison = s.duration
|
||||||
|
} else if s.name == "Recharge" {
|
||||||
|
if w.recharge > 0 {
|
||||||
|
return w, false
|
||||||
|
}
|
||||||
|
w.recharge = s.duration
|
||||||
|
}
|
||||||
|
w.playerMp -= s.mpCost
|
||||||
|
w.manaSpent += s.mpCost
|
||||||
|
return w, true
|
||||||
|
}
|
||||||
|
|
||||||
|
func copyState(w state) state {
|
||||||
|
ret := state{
|
||||||
|
bossHp: w.bossHp,
|
||||||
|
bossDmg: w.bossDmg,
|
||||||
|
playerHp: w.playerHp,
|
||||||
|
playerMp: w.playerMp,
|
||||||
|
playerDef: w.playerDef,
|
||||||
|
shield: w.shield,
|
||||||
|
poison: w.poison,
|
||||||
|
recharge: w.recharge,
|
||||||
|
manaSpent: w.manaSpent,
|
||||||
|
move: w.move,
|
||||||
|
}
|
||||||
|
return ret
|
||||||
|
}
|
||||||
|
|
||||||
|
func printState(w state) {
|
||||||
|
if w.move == playerTurn {
|
||||||
|
fmt.Println("*** Player Turn ***")
|
||||||
|
} else {
|
||||||
|
fmt.Println("*** Boss Turn ***")
|
||||||
|
}
|
||||||
|
fmt.Printf("Player - HP(%d) MP(%d)\n", w.playerHp, w.playerMp)
|
||||||
|
fmt.Printf("Boss - HP(%d) DMG(%d)\n", w.bossHp, w.bossDmg)
|
||||||
|
fmt.Printf("Shield(%d); Poison(%d); Recharge(%d)\n", w.shield, w.poison, w.recharge)
|
||||||
|
fmt.Printf("Mana Used: %d\n", w.manaSpent)
|
||||||
|
fmt.Println()
|
||||||
|
}
|
||||||
|
|
||||||
|
func decrementTimers(w state) state {
|
||||||
|
w.shield--
|
||||||
|
w.poison--
|
||||||
|
w.recharge--
|
||||||
|
return w
|
||||||
|
}
|
||||||
|
|
||||||
|
func initSpellBook() {
|
||||||
|
spellBook = append(spellBook, spell{
|
||||||
|
name: "Magic Missile",
|
||||||
|
mpCost: 53,
|
||||||
|
damage: 4,
|
||||||
|
})
|
||||||
|
spellBook = append(spellBook, spell{
|
||||||
|
name: "Drain",
|
||||||
|
mpCost: 73,
|
||||||
|
damage: 2,
|
||||||
|
heal: 2,
|
||||||
|
})
|
||||||
|
spellBook = append(spellBook, spell{
|
||||||
|
name: "Shield",
|
||||||
|
mpCost: 113,
|
||||||
|
duration: 6,
|
||||||
|
})
|
||||||
|
spellBook = append(spellBook, spell{
|
||||||
|
name: "Poison",
|
||||||
|
mpCost: 173,
|
||||||
|
duration: 6,
|
||||||
|
})
|
||||||
|
spellBook = append(spellBook, spell{
|
||||||
|
name: "Recharge",
|
||||||
|
mpCost: 229,
|
||||||
|
duration: 5,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
func itoa(i int) string {
|
||||||
|
return strconv.Itoa(i)
|
||||||
|
}
|
||||||
|
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
|
||||||
|
}
|
161
2015/day22/problem
Normal file
161
2015/day22/problem
Normal file
@ -0,0 +1,161 @@
|
|||||||
|
Advent of Code
|
||||||
|
|
||||||
|
br0xen 44*
|
||||||
|
|
||||||
|
• [About]
|
||||||
|
• [Stats]
|
||||||
|
• [Leaderboard]
|
||||||
|
• [Settings]
|
||||||
|
• [Log out]
|
||||||
|
|
||||||
|
--- Day 22: Wizard Simulator 20XX ---
|
||||||
|
|
||||||
|
Little Henry Case decides that defeating bosses with swords and stuff is boring. Now he's
|
||||||
|
playing the game with a wizard. Of course, he gets stuck on another boss and needs your help
|
||||||
|
again.
|
||||||
|
|
||||||
|
In this version, combat still proceeds with the player and the boss taking alternating turns.
|
||||||
|
The player still goes first. Now, however, you don't get any equipment; instead, you must
|
||||||
|
choose one of your spells to cast. The first character at or below 0 hit points loses.
|
||||||
|
|
||||||
|
Since you're a wizard, you don't get to wear armor, and you can't attack normally. However,
|
||||||
|
since you do magic damage, your opponent's armor is ignored, and so the boss effectively has
|
||||||
|
zero armor as well. As before, if armor (from a spell, in this case) would reduce damage below
|
||||||
|
1, it becomes 1 instead - that is, the boss' attacks always deal at least 1 damage.
|
||||||
|
|
||||||
|
On each of your turns, you must select one of your spells to cast. If you cannot afford to
|
||||||
|
cast any spell, you lose. Spells cost mana; you start with 500 mana, but have no maximum
|
||||||
|
limit. You must have enough mana to cast a spell, and its cost is immediately deducted when
|
||||||
|
you cast it. Your spells are Magic Missile, Drain, Shield, Poison, and Recharge.
|
||||||
|
|
||||||
|
• Magic Missile costs 53 mana. It instantly does 4 damage.
|
||||||
|
• Drain costs 73 mana. It instantly does 2 damage and heals you for 2 hit points.
|
||||||
|
• Shield costs 113 mana. It starts an effect that lasts for 6 turns. While it is active,
|
||||||
|
your armor is increased by 7.
|
||||||
|
• Poison costs 173 mana. It starts an effect that lasts for 6 turns. At the start of each
|
||||||
|
turn while it is active, it deals the boss 3 damage.
|
||||||
|
• Recharge costs 229 mana. It starts an effect that lasts for 5 turns. At the start of each
|
||||||
|
turn while it is active, it gives you 101 new mana.
|
||||||
|
|
||||||
|
Effects all work the same way. Effects apply at the start of both the player's turns and the
|
||||||
|
boss' turns. Effects are created with a timer (the number of turns they last); at the start of
|
||||||
|
each turn, after they apply any effect they have, their timer is decreased by one. If this
|
||||||
|
decreases the timer to zero, the effect ends. You cannot cast a spell that would start an
|
||||||
|
effect which is already active. However, effects can be started on the same turn they end.
|
||||||
|
|
||||||
|
For example, suppose the player has 10 hit points and 250 mana, and that the boss has 13 hit
|
||||||
|
points and 8 damage:
|
||||||
|
|
||||||
|
-- Player turn --
|
||||||
|
- Player has 10 hit points, 0 armor, 250 mana
|
||||||
|
- Boss has 13 hit points
|
||||||
|
Player casts Poison.
|
||||||
|
|
||||||
|
-- Boss turn --
|
||||||
|
- Player has 10 hit points, 0 armor, 77 mana
|
||||||
|
- Boss has 13 hit points
|
||||||
|
Poison deals 3 damage; its timer is now 5.
|
||||||
|
Boss attacks for 8 damage.
|
||||||
|
|
||||||
|
-- Player turn --
|
||||||
|
- Player has 2 hit points, 0 armor, 77 mana
|
||||||
|
- Boss has 10 hit points
|
||||||
|
Poison deals 3 damage; its timer is now 4.
|
||||||
|
Player casts Magic Missile, dealing 4 damage.
|
||||||
|
|
||||||
|
-- Boss turn --
|
||||||
|
- Player has 2 hit points, 0 armor, 24 mana
|
||||||
|
- Boss has 3 hit points
|
||||||
|
Poison deals 3 damage. This kills the boss, and the player wins.
|
||||||
|
|
||||||
|
Now, suppose the same initial conditions, except that the boss has 14 hit points instead:
|
||||||
|
|
||||||
|
-- Player turn --
|
||||||
|
- Player has 10 hit points, 0 armor, 250 mana
|
||||||
|
- Boss has 14 hit points
|
||||||
|
Player casts Recharge.
|
||||||
|
|
||||||
|
-- Boss turn --
|
||||||
|
- Player has 10 hit points, 0 armor, 21 mana
|
||||||
|
- Boss has 14 hit points
|
||||||
|
Recharge provides 101 mana; its timer is now 4.
|
||||||
|
Boss attacks for 8 damage!
|
||||||
|
|
||||||
|
-- Player turn --
|
||||||
|
- Player has 2 hit points, 0 armor, 122 mana
|
||||||
|
- Boss has 14 hit points
|
||||||
|
Recharge provides 101 mana; its timer is now 3.
|
||||||
|
Player casts Shield, increasing armor by 7.
|
||||||
|
|
||||||
|
-- Boss turn --
|
||||||
|
- Player has 2 hit points, 7 armor, 110 mana
|
||||||
|
- Boss has 14 hit points
|
||||||
|
Shield's timer is now 5.
|
||||||
|
Recharge provides 101 mana; its timer is now 2.
|
||||||
|
Boss attacks for 8 - 7 = 1 damage!
|
||||||
|
|
||||||
|
-- Player turn --
|
||||||
|
- Player has 1 hit point, 7 armor, 211 mana
|
||||||
|
- Boss has 14 hit points
|
||||||
|
Shield's timer is now 4.
|
||||||
|
Recharge provides 101 mana; its timer is now 1.
|
||||||
|
Player casts Drain, dealing 2 damage, and healing 2 hit points.
|
||||||
|
|
||||||
|
-- Boss turn --
|
||||||
|
- Player has 3 hit points, 7 armor, 239 mana
|
||||||
|
- Boss has 12 hit points
|
||||||
|
Shield's timer is now 3.
|
||||||
|
Recharge provides 101 mana; its timer is now 0.
|
||||||
|
Recharge wears off.
|
||||||
|
Boss attacks for 8 - 7 = 1 damage!
|
||||||
|
|
||||||
|
-- Player turn --
|
||||||
|
- Player has 2 hit points, 7 armor, 340 mana
|
||||||
|
- Boss has 12 hit points
|
||||||
|
Shield's timer is now 2.
|
||||||
|
Player casts Poison.
|
||||||
|
|
||||||
|
-- Boss turn --
|
||||||
|
- Player has 2 hit points, 7 armor, 167 mana
|
||||||
|
- Boss has 12 hit points
|
||||||
|
Shield's timer is now 1.
|
||||||
|
Poison deals 3 damage; its timer is now 5.
|
||||||
|
Boss attacks for 8 - 7 = 1 damage!
|
||||||
|
|
||||||
|
-- Player turn --
|
||||||
|
- Player has 1 hit point, 7 armor, 167 mana
|
||||||
|
- Boss has 9 hit points
|
||||||
|
Shield's timer is now 0.
|
||||||
|
Shield wears off, decreasing armor by 7.
|
||||||
|
Poison deals 3 damage; its timer is now 4.
|
||||||
|
Player casts Magic Missile, dealing 4 damage.
|
||||||
|
|
||||||
|
-- Boss turn --
|
||||||
|
- Player has 1 hit point, 0 armor, 114 mana
|
||||||
|
- Boss has 2 hit points
|
||||||
|
Poison deals 3 damage. This kills the boss, and the player wins.
|
||||||
|
|
||||||
|
You start with 50 hit points and 500 mana points. The boss's actual stats are in your puzzle
|
||||||
|
input. What is the least amount of mana you can spend and still win the fight? (Do not include
|
||||||
|
mana recharge effects as "spending" negative mana.)
|
||||||
|
|
||||||
|
To begin, get your puzzle input.
|
||||||
|
|
||||||
|
Answer: _____________________ [ [Submit] ]
|
||||||
|
|
||||||
|
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/day/21
|
||||||
|
. http://adventofcode.com/day/22/input
|
||||||
|
. https://twitter.com/intent/tweet?text=%22Wizard+Simulator+20XX%22+%2D+Day+22+%2D+Advent+of+Code&url=http%3A%2F%2Fadventofcode%2Ecom%2Fday%2F22&related=ericwastl&hashtags=AdventOfCode
|
||||||
|
. https://plus.google.com/share?url=http%3A%2F%2Fadventofcode%2Ecom%2Fday%2F22
|
||||||
|
. http://www.reddit.com/submit?url=http%3A%2F%2Fadventofcode%2Ecom%2Fday%2F22&title=%22Wizard+Simulator+20XX%22+%2D+Day+22+%2D+Advent+of+Code
|
48
2015/day23/input
Normal file
48
2015/day23/input
Normal file
@ -0,0 +1,48 @@
|
|||||||
|
jio a, +22
|
||||||
|
inc a
|
||||||
|
tpl a
|
||||||
|
tpl a
|
||||||
|
tpl a
|
||||||
|
inc a
|
||||||
|
tpl a
|
||||||
|
inc a
|
||||||
|
tpl a
|
||||||
|
inc a
|
||||||
|
inc a
|
||||||
|
tpl a
|
||||||
|
inc a
|
||||||
|
inc a
|
||||||
|
tpl a
|
||||||
|
inc a
|
||||||
|
inc a
|
||||||
|
tpl a
|
||||||
|
inc a
|
||||||
|
inc a
|
||||||
|
tpl a
|
||||||
|
jmp +19
|
||||||
|
tpl a
|
||||||
|
tpl a
|
||||||
|
tpl a
|
||||||
|
tpl a
|
||||||
|
inc a
|
||||||
|
inc a
|
||||||
|
tpl a
|
||||||
|
inc a
|
||||||
|
tpl a
|
||||||
|
inc a
|
||||||
|
inc a
|
||||||
|
tpl a
|
||||||
|
inc a
|
||||||
|
inc a
|
||||||
|
tpl a
|
||||||
|
inc a
|
||||||
|
tpl a
|
||||||
|
tpl a
|
||||||
|
jio a, +8
|
||||||
|
inc b
|
||||||
|
jie a, +4
|
||||||
|
tpl a
|
||||||
|
inc a
|
||||||
|
jmp +2
|
||||||
|
hlf a
|
||||||
|
jmp -7
|
103
2015/day23/main.go
Normal file
103
2015/day23/main.go
Normal file
@ -0,0 +1,103 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bufio"
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
"strconv"
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
|
var registers map[string]int
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
registers = make(map[string]int)
|
||||||
|
if len(os.Args) > 1 {
|
||||||
|
if os.Args[1] == "-help" {
|
||||||
|
fmt.Println("Usage: day23 [register presets]")
|
||||||
|
fmt.Println(" Register presets are given in the form:")
|
||||||
|
fmt.Println(" name=value")
|
||||||
|
fmt.Println(" If more than one, separate with spaces.")
|
||||||
|
fmt.Println(" If none are given, all registers start at 0")
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
for i := range os.Args {
|
||||||
|
if strings.Contains(os.Args[i], "=") {
|
||||||
|
presets := strings.Split(os.Args[i], "=")
|
||||||
|
registers[presets[0]] = mustAtoi(presets[1])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
var input []string
|
||||||
|
scanner := bufio.NewScanner(os.Stdin)
|
||||||
|
for scanner.Scan() {
|
||||||
|
input = append(input, strings.ToLower(scanner.Text()))
|
||||||
|
}
|
||||||
|
// We manually manage i
|
||||||
|
var i, cnt int
|
||||||
|
for i < len(input) {
|
||||||
|
printRegisters()
|
||||||
|
fmt.Print(" ")
|
||||||
|
cnt++
|
||||||
|
fmt.Print(input[i])
|
||||||
|
parts := strings.Split(input[i], " ")
|
||||||
|
switch parts[0] {
|
||||||
|
case "hlf":
|
||||||
|
registers[parts[1]] = registers[parts[1]] / 2
|
||||||
|
i++
|
||||||
|
case "tpl":
|
||||||
|
registers[parts[1]] = registers[parts[1]] * 3
|
||||||
|
i++
|
||||||
|
case "inc":
|
||||||
|
registers[parts[1]]++
|
||||||
|
i++
|
||||||
|
case "jmp":
|
||||||
|
i += mustAtoi(parts[1])
|
||||||
|
case "jie":
|
||||||
|
parts[1] = string(parts[1][len(parts[1])-2])
|
||||||
|
if registers[parts[1]]%2 == 0 {
|
||||||
|
i += mustAtoi(parts[2])
|
||||||
|
} else {
|
||||||
|
i++
|
||||||
|
}
|
||||||
|
case "jio":
|
||||||
|
parts[1] = string(parts[1][len(parts[1])-2])
|
||||||
|
if registers[parts[1]] == 1 {
|
||||||
|
i += mustAtoi(parts[2])
|
||||||
|
} else {
|
||||||
|
i++
|
||||||
|
}
|
||||||
|
}
|
||||||
|
fmt.Print(" ")
|
||||||
|
printRegistersLn()
|
||||||
|
}
|
||||||
|
printRegistersLn()
|
||||||
|
}
|
||||||
|
|
||||||
|
func printRegistersLn() {
|
||||||
|
printRegisters()
|
||||||
|
fmt.Println()
|
||||||
|
}
|
||||||
|
|
||||||
|
func printRegisters() {
|
||||||
|
fmt.Print("[")
|
||||||
|
for k := range registers {
|
||||||
|
printRegister(k)
|
||||||
|
fmt.Print(" ")
|
||||||
|
}
|
||||||
|
fmt.Print("]")
|
||||||
|
}
|
||||||
|
|
||||||
|
func printRegister(n string) {
|
||||||
|
fmt.Print(n + ": " + strconv.Itoa(registers[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
|
||||||
|
}
|
78
2015/day23/problem
Normal file
78
2015/day23/problem
Normal file
@ -0,0 +1,78 @@
|
|||||||
|
Advent of Code
|
||||||
|
|
||||||
|
br0xen 43*
|
||||||
|
|
||||||
|
• [About]
|
||||||
|
• [Stats]
|
||||||
|
• [Leaderboard]
|
||||||
|
• [Settings]
|
||||||
|
• [Log out]
|
||||||
|
|
||||||
|
--- Day 23: Opening the Turing Lock ---
|
||||||
|
|
||||||
|
Little Jane Marie just got her very first computer for Christmas from some unknown benefactor.
|
||||||
|
It comes with instructions and an example program, but the computer itself seems to be
|
||||||
|
malfunctioning. She's curious what the program does, and would like you to help her run it.
|
||||||
|
|
||||||
|
The manual explains that the computer supports two registers and six instructions (truly, it
|
||||||
|
goes on to remind the reader, a state-of-the-art technology). The registers are named a and b,
|
||||||
|
can hold any non-negative integer, and begin with a value of 0. The instructions are as
|
||||||
|
follows:
|
||||||
|
|
||||||
|
• hlf r sets register r to half its current value, then continues with the next instruction.
|
||||||
|
• tpl r sets register r to triple its current value, then continues with the next
|
||||||
|
instruction.
|
||||||
|
• inc r increments register r, adding 1 to it, then continues with the next instruction.
|
||||||
|
• jmp offset is a jump; it continues with the instruction offset away relative to itself.
|
||||||
|
• jie r, offset is like jmp, but only jumps if register r is even ("jump if even").
|
||||||
|
• jio r, offset is like jmp, but only jumps if register r is 1 ("jump if one", not odd).
|
||||||
|
|
||||||
|
All three jump instructions work with an offset relative to that instruction. The offset is
|
||||||
|
always written with a prefix + or - to indicate the direction of the jump (forward or
|
||||||
|
backward, respectively). For example, jmp +1 would simply continue with the next instruction,
|
||||||
|
while jmp +0 would continuously jump back to itself forever.
|
||||||
|
|
||||||
|
The program exits when it tries to run an instruction beyond the ones defined.
|
||||||
|
|
||||||
|
For example, this program sets a to 2, because the jio instruction causes it to skip the tpl
|
||||||
|
instruction:
|
||||||
|
|
||||||
|
inc a
|
||||||
|
jio a, +2
|
||||||
|
tpl a
|
||||||
|
inc a
|
||||||
|
|
||||||
|
What is the value in register b when the program in your puzzle input is finished executing?
|
||||||
|
|
||||||
|
Your puzzle answer was 255.
|
||||||
|
|
||||||
|
The first half of this puzzle is complete! It provides one gold star: *
|
||||||
|
|
||||||
|
--- Part Two ---
|
||||||
|
|
||||||
|
The unknown benefactor is very thankful for releasi-- er, helping little Jane Marie with her
|
||||||
|
computer. Definitely not to distract you, what is the value in register b after the program is
|
||||||
|
finished executing if register a starts as 1 instead?
|
||||||
|
|
||||||
|
Although it hasn't changed, you can still get your puzzle input.
|
||||||
|
|
||||||
|
Answer: _____________________ [ [Submit] ]
|
||||||
|
|
||||||
|
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
|
||||||
|
. https://en.wikipedia.org/wiki/Processor_register
|
||||||
|
. https://en.wikipedia.org/wiki/Instruction_set
|
||||||
|
. https://en.wikipedia.org/wiki/Natural_number
|
||||||
|
. http://adventofcode.com/day/23/input
|
||||||
|
. https://twitter.com/intent/tweet?text=I%27ve+completed+Part+One+of+%22Opening+the+Turing+Lock%22+%2D+Day+23+%2D+Advent+of+Code&url=http%3A%2F%2Fadventofcode%2Ecom%2Fday%2F23&related=ericwastl&hashtags=AdventOfCode
|
||||||
|
. https://plus.google.com/share?url=http%3A%2F%2Fadventofcode%2Ecom%2Fday%2F23
|
||||||
|
. http://www.reddit.com/submit?url=http%3A%2F%2Fadventofcode%2Ecom%2Fday%2F23&title=I%27ve+completed+Part+One+of+%22Opening+the+Turing+Lock%22+%2D+Day+23+%2D+Advent+of+Code
|
28
2015/day24/input
Normal file
28
2015/day24/input
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
1
|
||||||
|
3
|
||||||
|
5
|
||||||
|
11
|
||||||
|
13
|
||||||
|
17
|
||||||
|
19
|
||||||
|
23
|
||||||
|
29
|
||||||
|
31
|
||||||
|
37
|
||||||
|
41
|
||||||
|
43
|
||||||
|
47
|
||||||
|
53
|
||||||
|
59
|
||||||
|
67
|
||||||
|
71
|
||||||
|
73
|
||||||
|
79
|
||||||
|
83
|
||||||
|
89
|
||||||
|
97
|
||||||
|
101
|
||||||
|
103
|
||||||
|
107
|
||||||
|
109
|
||||||
|
113
|
142
2015/day24/main.go
Normal file
142
2015/day24/main.go
Normal file
@ -0,0 +1,142 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bufio"
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
"strconv"
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
|
var pkgWeights []int64
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
scanner := bufio.NewScanner(os.Stdin)
|
||||||
|
for scanner.Scan() {
|
||||||
|
pkgWeights = append(pkgWeights, int64(mustAtoi(strings.ToLower(scanner.Text()))))
|
||||||
|
}
|
||||||
|
// Sort the weights, in the case of our input, no need.
|
||||||
|
totalWeight := weighPackages(pkgWeights)
|
||||||
|
// For Part 1:
|
||||||
|
//splitWeight := totalWeight / 3
|
||||||
|
// For Part 2:
|
||||||
|
splitWeight := totalWeight / 4
|
||||||
|
fmt.Printf("Balanced at %d\n", splitWeight)
|
||||||
|
// Now find the fewest number of packages that are that weight
|
||||||
|
result := tryPackages([]int64{}, pkgWeights, splitWeight)
|
||||||
|
fmt.Println("*** RESULT ***")
|
||||||
|
//result = makeUnique(result)
|
||||||
|
lowestQE := int64(-1)
|
||||||
|
shortest := -1
|
||||||
|
for i := range result {
|
||||||
|
if len(result[i]) <= shortest || shortest == -1 {
|
||||||
|
fmt.Print(result[i])
|
||||||
|
fmt.Printf(" L:%d", len(result[i]))
|
||||||
|
fmt.Printf(" QE:%d\n", getQE(result[i]))
|
||||||
|
shortest = len(result[i])
|
||||||
|
if getQE(result[i]) < lowestQE || lowestQE == -1 {
|
||||||
|
lowestQE = getQE(result[i])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
fmt.Println()
|
||||||
|
fmt.Printf("%d\n", lowestQE)
|
||||||
|
}
|
||||||
|
|
||||||
|
func tryPackages(pkgs []int64, rem []int64, targ int64) [][]int64 {
|
||||||
|
// Go through all packages in 'rem' and find the combination
|
||||||
|
// That results in the least total number of packages
|
||||||
|
var findRet [][]int64
|
||||||
|
fewest := -1
|
||||||
|
if len(pkgs) > fewest && fewest != -1 {
|
||||||
|
return findRet
|
||||||
|
}
|
||||||
|
for i := len(rem) - 1; i >= 0; i-- {
|
||||||
|
t := targ - weighPackages(pkgs)
|
||||||
|
if rem[i] <= t {
|
||||||
|
tryPkgs := append(pkgs, rem[i])
|
||||||
|
if weighPackages(tryPkgs) == targ {
|
||||||
|
//if len(tryPkgs) <= fewest || fewest == -1 {
|
||||||
|
findRet = append(findRet, tryPkgs)
|
||||||
|
// fewest = len(tryPkgs)
|
||||||
|
//}
|
||||||
|
}
|
||||||
|
// Not there yet... Recurse
|
||||||
|
rem = rem[:i]
|
||||||
|
res := tryPackages(tryPkgs, rem, targ)
|
||||||
|
for i := range res {
|
||||||
|
if weighPackages(res[i]) == targ {
|
||||||
|
//if len(res[i]) <= fewest || fewest == -1 {
|
||||||
|
findRet = append(findRet, res[i])
|
||||||
|
// fewest = len(res[i])
|
||||||
|
//}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return findRet
|
||||||
|
}
|
||||||
|
|
||||||
|
func getQE(pkgs []int64) int64 {
|
||||||
|
var totalQE int64
|
||||||
|
for i := range pkgs {
|
||||||
|
if totalQE == 0 {
|
||||||
|
totalQE = int64(pkgs[i])
|
||||||
|
} else {
|
||||||
|
totalQE = totalQE * int64(pkgs[i])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return totalQE
|
||||||
|
}
|
||||||
|
|
||||||
|
func weighPackages(pkgs []int64) int64 {
|
||||||
|
var totalWeight int64
|
||||||
|
for i := range pkgs {
|
||||||
|
totalWeight += pkgs[i]
|
||||||
|
}
|
||||||
|
return totalWeight
|
||||||
|
}
|
||||||
|
|
||||||
|
func makeUnique(s [][]int64) [][]int64 {
|
||||||
|
var ret [][]int64
|
||||||
|
for i := range s {
|
||||||
|
var found bool
|
||||||
|
// Check if s[i] is already in ret
|
||||||
|
for j := range ret {
|
||||||
|
if isSame(ret[j], s[i]) {
|
||||||
|
found = true
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if !found {
|
||||||
|
ret = append(ret, s[i])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ret
|
||||||
|
}
|
||||||
|
|
||||||
|
func isSame(s1 []int64, s2 []int64) bool {
|
||||||
|
if len(s1) != len(s2) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
for i := range s1 {
|
||||||
|
if s1[i] != s2[i] {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
func itoa(i int) string {
|
||||||
|
return strconv.Itoa(i)
|
||||||
|
}
|
||||||
|
|
||||||
|
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
|
||||||
|
}
|
116
2015/day24/problem
Normal file
116
2015/day24/problem
Normal file
@ -0,0 +1,116 @@
|
|||||||
|
Advent of Code
|
||||||
|
|
||||||
|
br0xen 50*
|
||||||
|
|
||||||
|
• [About]
|
||||||
|
• [Stats]
|
||||||
|
• [Leaderboard]
|
||||||
|
• [Settings]
|
||||||
|
• [Log out]
|
||||||
|
|
||||||
|
--- Day 24: It Hangs in the Balance ---
|
||||||
|
|
||||||
|
It's Christmas Eve, and Santa is loading up the sleigh for this year's deliveries. However,
|
||||||
|
there's one small problem: he can't get the sleigh to balance. If it isn't balanced, he can't
|
||||||
|
defy physics, and nobody gets presents this year.
|
||||||
|
|
||||||
|
No pressure.
|
||||||
|
|
||||||
|
Santa has provided you a list of the weights of every package he needs to fit on the sleigh.
|
||||||
|
The packages need to be split into three groups of exactly the same weight, and every package
|
||||||
|
has to fit. The first group goes in the passenger compartment of the sleigh, and the second
|
||||||
|
and third go in containers on either side. Only when all three groups weigh exactly the same
|
||||||
|
amount will the sleigh be able to fly. Defying physics has rules, you know!
|
||||||
|
|
||||||
|
Of course, that's not the only problem. The first group - the one going in the passenger
|
||||||
|
compartment - needs as few packages as possible so that Santa has some legroom left over. It
|
||||||
|
doesn't matter how many packages are in either of the other two groups, so long as all of the
|
||||||
|
groups weigh the same.
|
||||||
|
|
||||||
|
Furthermore, Santa tells you, if there are multiple ways to arrange the packages such that the
|
||||||
|
fewest possible are in the first group, you need to choose the way where the first group has
|
||||||
|
the smallest quantum entanglement to reduce the chance of any "complications". The quantum
|
||||||
|
entanglement of a group of packages is the product of their weights, that is, the value you
|
||||||
|
get when you multiply their weights together. Only consider quantum entanglement if the first
|
||||||
|
group has the fewest possible number of packages in it and all groups weigh the same amount.
|
||||||
|
|
||||||
|
For example, suppose you have ten packages with weights 1 through 5 and 7 through 11. For this
|
||||||
|
situation, some of the unique first groups, their quantum entanglements, and a way to divide
|
||||||
|
the remaining packages are as follows:
|
||||||
|
|
||||||
|
Group 1; Group 2; Group 3
|
||||||
|
11 9 (QE= 99); 10 8 2; 7 5 4 3 1
|
||||||
|
10 9 1 (QE= 90); 11 7 2; 8 5 4 3
|
||||||
|
10 8 2 (QE=160); 11 9; 7 5 4 3 1
|
||||||
|
10 7 3 (QE=210); 11 9; 8 5 4 2 1
|
||||||
|
10 5 4 1 (QE=200); 11 9; 8 7 3 2
|
||||||
|
10 5 3 2 (QE=300); 11 9; 8 7 4 1
|
||||||
|
10 4 3 2 1 (QE=240); 11 9; 8 7 5
|
||||||
|
9 8 3 (QE=216); 11 7 2; 10 5 4 1
|
||||||
|
9 7 4 (QE=252); 11 8 1; 10 5 3 2
|
||||||
|
9 5 4 2 (QE=360); 11 8 1; 10 7 3
|
||||||
|
8 7 5 (QE=280); 11 9; 10 4 3 2 1
|
||||||
|
8 5 4 3 (QE=480); 11 9; 10 7 2 1
|
||||||
|
7 5 4 3 1 (QE=420); 11 9; 10 8 2
|
||||||
|
|
||||||
|
Of these, although 10 9 1 has the smallest quantum entanglement (90), the configuration with
|
||||||
|
only two packages, 11 9, in the passenger compartment gives Santa the most legroom and wins.
|
||||||
|
In this situation, the quantum entanglement for the ideal configuration is therefore 99. Had
|
||||||
|
there been two configurations with only two packages in the first group, the one with the
|
||||||
|
smaller quantum entanglement would be chosen.
|
||||||
|
|
||||||
|
What is the quantum entanglement of the first group of packages in the ideal configuration?
|
||||||
|
|
||||||
|
Your puzzle answer was 10439961859.
|
||||||
|
|
||||||
|
--- Part Two ---
|
||||||
|
|
||||||
|
That's weird... the sleigh still isn't balancing.
|
||||||
|
|
||||||
|
"Ho ho ho", Santa muses to himself. "I forgot the trunk".
|
||||||
|
|
||||||
|
Balance the sleigh again, but this time, separate the packages into four groups instead of
|
||||||
|
three. The other constraints still apply.
|
||||||
|
|
||||||
|
Given the example packages above, this would be some of the new unique first groups, their
|
||||||
|
quantum entanglements, and one way to divide the remaining packages:
|
||||||
|
|
||||||
|
11 4 (QE=44); 10 5; 9 3 2 1; 8 7
|
||||||
|
10 5 (QE=50); 11 4; 9 3 2 1; 8 7
|
||||||
|
9 5 1 (QE=45); 11 4; 10 3 2; 8 7
|
||||||
|
9 4 2 (QE=72); 11 3 1; 10 5; 8 7
|
||||||
|
9 3 2 1 (QE=54); 11 4; 10 5; 8 7
|
||||||
|
8 7 (QE=56); 11 4; 10 5; 9 3 2 1
|
||||||
|
|
||||||
|
Of these, there are three arrangements that put the minimum (two) number of packages in the
|
||||||
|
first group: 11 4, 10 5, and 8 7. Of these, 11 4 has the lowest quantum entanglement, and so
|
||||||
|
it is selected.
|
||||||
|
|
||||||
|
Now, what is the quantum entanglement of the first group of packages in the ideal
|
||||||
|
configuration?
|
||||||
|
|
||||||
|
Your puzzle answer was 72050269.
|
||||||
|
|
||||||
|
Both parts of this puzzle are complete! They provide two gold stars: **
|
||||||
|
|
||||||
|
At this point, all that is left is for you to admire your advent calendar.
|
||||||
|
|
||||||
|
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
|
||||||
|
. https://en.wikipedia.org/wiki/Product_%28mathematics%29
|
||||||
|
. http://adventofcode.com/
|
||||||
|
. http://adventofcode.com/day/24/input
|
||||||
|
. https://twitter.com/intent/tweet?text=I%27ve+completed+%22It+Hangs+in+the+Balance%22+%2D+Day+24+%2D+Advent+of+Code&url=http%3A%2F%2Fadventofcode%2Ecom%2Fday%2F24&related=ericwastl&hashtags=AdventOfCode
|
||||||
|
. https://plus.google.com/share?url=http%3A%2F%2Fadventofcode%2Ecom%2Fday%2F24
|
||||||
|
. http://www.reddit.com/submit?url=http%3A%2F%2Fadventofcode%2Ecom%2Fday%2F24&title=I%27ve+completed+%22It+Hangs+in+the+Balance%22+%2D+Day+24+%2D+Advent+of+Code
|
10
2015/day24/sample_input
Normal file
10
2015/day24/sample_input
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
1
|
||||||
|
2
|
||||||
|
3
|
||||||
|
4
|
||||||
|
5
|
||||||
|
7
|
||||||
|
8
|
||||||
|
9
|
||||||
|
10
|
||||||
|
11
|
1
2015/day25/input
Normal file
1
2015/day25/input
Normal file
@ -0,0 +1 @@
|
|||||||
|
To continue, please consult the code grid in the manual. Enter the code at row 2947, column 3029.
|
55
2015/day25/main.go
Normal file
55
2015/day25/main.go
Normal file
@ -0,0 +1,55 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
"strconv"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
if len(os.Args) < 2 || os.Args[1] == "-help" {
|
||||||
|
fmt.Println("Usage: day25 <row> <col>")
|
||||||
|
fmt.Println(" or: day25 <code number>")
|
||||||
|
}
|
||||||
|
row := mustAtoi(os.Args[1])
|
||||||
|
if len(os.Args) == 2 {
|
||||||
|
fmt.Printf("%d\n", genCodeNum(row))
|
||||||
|
os.Exit(0)
|
||||||
|
}
|
||||||
|
// Must be row/col request
|
||||||
|
col := mustAtoi(os.Args[2])
|
||||||
|
fmt.Printf("%d\n", genCodeNum(codeNumFromRowCol(row, col)))
|
||||||
|
}
|
||||||
|
|
||||||
|
func codeNumFromRowCol(r int, c int) int {
|
||||||
|
if r == 1 {
|
||||||
|
if c == 1 {
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
return c + codeNumFromRowCol(r, c-1)
|
||||||
|
}
|
||||||
|
if c == 1 {
|
||||||
|
return codeNumFromRowCol(1, (r-1)) + 1
|
||||||
|
}
|
||||||
|
return codeNumFromRowCol((r+1), (c-1)) + 1
|
||||||
|
}
|
||||||
|
|
||||||
|
func genCodeNum(i int) int64 {
|
||||||
|
ret := int64(20151125)
|
||||||
|
for i > 1 {
|
||||||
|
ret *= 252533
|
||||||
|
ret = ret % 33554393
|
||||||
|
i--
|
||||||
|
}
|
||||||
|
return ret
|
||||||
|
}
|
||||||
|
|
||||||
|
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
|
||||||
|
}
|
106
2015/day25/problem
Normal file
106
2015/day25/problem
Normal file
@ -0,0 +1,106 @@
|
|||||||
|
Advent of Code
|
||||||
|
|
||||||
|
br0xen 46*
|
||||||
|
|
||||||
|
• [About]
|
||||||
|
• [Stats]
|
||||||
|
• [Leaderboard]
|
||||||
|
• [Settings]
|
||||||
|
• [Log out]
|
||||||
|
|
||||||
|
--- Day 25: Let It Snow ---
|
||||||
|
|
||||||
|
Merry Christmas! Santa is booting up his weather machine; looks like you might get a white
|
||||||
|
Christmas after all.
|
||||||
|
|
||||||
|
The weather machine beeps! On the console of the machine is a copy protection message asking
|
||||||
|
you to enter a code from the instruction manual. Apparently, it refuses to run unless you give
|
||||||
|
it that code. No problem; you'll just look up the code in the--
|
||||||
|
|
||||||
|
"Ho ho ho", Santa ponders aloud. "I can't seem to find the manual."
|
||||||
|
|
||||||
|
You look up the support number for the manufacturer and give them a call. Good thing, too -
|
||||||
|
that 49th star wasn't going to earn itself.
|
||||||
|
|
||||||
|
"Oh, that machine is quite old!", they tell you. "That model went out of support six minutes
|
||||||
|
ago, and we just finished shredding all of the manuals. I bet we can find you the code
|
||||||
|
generation algorithm, though."
|
||||||
|
|
||||||
|
After putting you on hold for twenty minutes (your call is very important to them, it reminded
|
||||||
|
you repeatedly), they finally find an engineer that remembers how the code system works.
|
||||||
|
|
||||||
|
The codes are printed on an infinite sheet of paper, starting in the top-left corner. The
|
||||||
|
codes are filled in by diagonals: starting with the first row with an empty first box, the
|
||||||
|
codes are filled in diagonally up and to the right. This process repeats until the infinite
|
||||||
|
paper is covered. So, the first few codes are filled in in this order:
|
||||||
|
|
||||||
|
| 1 2 3 4 5 6
|
||||||
|
---+---+---+---+---+---+---+
|
||||||
|
1 | 1 3 6 10 15 21
|
||||||
|
2 | 2 5 9 14 20
|
||||||
|
3 | 4 8 13 19
|
||||||
|
4 | 7 12 18
|
||||||
|
5 | 11 17
|
||||||
|
6 | 16
|
||||||
|
|
||||||
|
For example, the 12th code would be written to row 4, column 2; the 15th code would be written
|
||||||
|
to row 1, column 5.
|
||||||
|
|
||||||
|
The voice on the other end of the phone continues with how the codes are actually generated.
|
||||||
|
The first code is 20151125. After that, each code is generated by taking the previous one,
|
||||||
|
multiplying it by 252533, and then keeping the remainder from dividing that value by 33554393.
|
||||||
|
|
||||||
|
So, to find the second code (which ends up in row 2, column 1), start with the previous value,
|
||||||
|
20151125. Multiply it by 252533 to get 5088824049625. Then, divide that by 33554393, which
|
||||||
|
leaves a remainder of 31916031. That remainder is the second code.
|
||||||
|
|
||||||
|
"Oh!", says the voice. "It looks like we missed a scrap from one of the manuals. Let me read
|
||||||
|
it to you." You write down his numbers:
|
||||||
|
|
||||||
|
| 1 2 3 4 5 6
|
||||||
|
---+---------+---------+---------+---------+---------+---------+
|
||||||
|
1 | 20151125 18749137 17289845 30943339 10071777 33511524
|
||||||
|
2 | 31916031 21629792 16929656 7726640 15514188 4041754
|
||||||
|
3 | 16080970 8057251 1601130 7981243 11661866 16474243
|
||||||
|
4 | 24592653 32451966 21345942 9380097 10600672 31527494
|
||||||
|
5 | 77061 17552253 28094349 6899651 9250759 31663883
|
||||||
|
6 | 33071741 6796745 25397450 24659492 1534922 27995004
|
||||||
|
|
||||||
|
"Now remember", the voice continues, "that's not even all of the first few numbers; for
|
||||||
|
example, you're missing the one at 7,1 that would come before 6,2. But, it should be enough to
|
||||||
|
let your-- oh, it's time for lunch! Bye!" The call disconnects.
|
||||||
|
|
||||||
|
Santa looks nervous. Your puzzle input contains the message on the machine's console. What
|
||||||
|
code do you give the machine?
|
||||||
|
|
||||||
|
Your puzzle answer was 19980801.
|
||||||
|
|
||||||
|
The first half of this puzzle is complete! It provides one gold star: *
|
||||||
|
|
||||||
|
--- Part Two ---
|
||||||
|
|
||||||
|
The machine springs to life, then falls silent again. It beeps. "Insufficient fuel", the
|
||||||
|
console reads. "Fifty stars are required before proceeding. One star is available."
|
||||||
|
|
||||||
|
..."one star is available"? You check the fuel tank; sure enough, a lone star sits at the
|
||||||
|
bottom, awaiting its friends. Looks like you need to provide 49 yourself.
|
||||||
|
|
||||||
|
You don't have enough stars to start the machine, though. You need x more.
|
||||||
|
|
||||||
|
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/day/1
|
||||||
|
. https://en.wikipedia.org/wiki/Copy_protection#Early_video_games
|
||||||
|
. https://en.wikipedia.org/wiki/Cantor's_diagonal_argument
|
||||||
|
. https://twitter.com/intent/tweet?text=I%27ve+completed+Part+One+of+%22Let+It+Snow%22+%2D+Day+25+%2D+Advent+of+Code&url=http%3A%2F%2Fadventofcode%2Ecom%2Fday%2F25&related=ericwastl&hashtags=AdventOfCode
|
||||||
|
. https://plus.google.com/share?url=http%3A%2F%2Fadventofcode%2Ecom%2Fday%2F25
|
||||||
|
. http://www.reddit.com/submit?url=http%3A%2F%2Fadventofcode%2Ecom%2Fday%2F25&title=I%27ve+completed+Part+One+of+%22Let+It+Snow%22+%2D+Day+25+%2D+Advent+of+Code
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user