-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
42 lines (36 loc) · 918 Bytes
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
// Package day02 - Solution for Advent of Code 2019/02
// Problem Link: http://adventofcode.com/2019/day/02
package day02
import (
_ "embed"
"fmt"
"github.com/code-shoily/aocgo/year19/intcode"
)
//go:embed input.txt
var input string
// Run prints out the result of the solution.
func Run() {
fmt.Println(solve(input))
}
func solve(input string) (int, int) {
return solvePart1(input), solvePart2(input)
}
func solvePart1(input string) int {
program := intcode.InitializeProgram(input, 0)
program.ProvideInitialParameters(12, 2)
program.Run()
return program.Output()
}
func solvePart2(input string) int {
for noun := 0; noun <= 99; noun++ {
for verb := 0; verb <= 99; verb++ {
program := intcode.InitializeProgram(input, 0)
program.ProvideInitialParameters(noun, verb)
program.Run()
if program.Output() == 19_690_720 {
return 100*noun + verb
}
}
}
panic("Invalid instruction")
}