~xenrox/aoc2019

a622219bc33fe46c1bb7f4f364c2a79f08494898 — Thorben Günther 4 years ago 9aec8d3
Finish 2/2
1 files changed, 24 insertions(+), 5 deletions(-)

M 2/main.go
M 2/main.go => 2/main.go +24 -5
@@ 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)
			}
		}
	}
}