@@ 20,7 20,7 @@ func calcOpcode(lines []int) int {
case 2:
lines[lines[pos+3]] = lines[lines[pos+1]] * lines[lines[pos+2]]
default:
- fmt.Println("Error")
+ // fmt.Println("Error")
return 0
}
pos += 4
@@ 45,10 45,29 @@ func parseInput(file string) []int {
return lines
}
+func startInput(noun int, verb int, list []int) []int {
+ list[1] = noun
+ list[2] = verb
+ return list
+}
+
func main() {
lines := parseInput("input.txt")
- lines[1] = 12
- lines[2] = 2
- fmt.Println(lines)
- fmt.Println(calcOpcode(lines))
+ input := make([]int, len(lines))
+ copy(input, lines)
+ input = startInput(12, 2, input)
+ fmt.Println(calcOpcode(input))
+
+ // Part 2
+ goal := 19690720
+ for noun := 0; noun <= 99; noun++ {
+ for verb := 0; verb <= 99; verb++ {
+ copy(input, lines)
+ input = startInput(noun, verb, input)
+ result := calcOpcode(input)
+ if result == goal {
+ fmt.Println(noun*100 + verb)
+ }
+ }
+ }
}