From a622219bc33fe46c1bb7f4f364c2a79f08494898 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thorben=20G=C3=BCnther?= Date: Sun, 22 Dec 2019 21:58:02 +0100 Subject: [PATCH] Finish 2/2 --- 2/main.go | 29 ++++++++++++++++++++++++----- 1 file changed, 24 insertions(+), 5 deletions(-) diff --git a/2/main.go b/2/main.go index ff80356..95243c6 100644 --- a/2/main.go +++ b/2/main.go @@ -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) + } + } + } } -- 2.44.0