Combine AoC Repos
This commit is contained in:
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
|
Reference in New Issue
Block a user