Finish part 2 of day 2

This commit is contained in:
Alphyron 2019-12-03 08:46:39 +01:00
parent 1680aec3ad
commit 4f48f24c74

View File

@ -32,12 +32,39 @@ func main() {
}
t2 = append(t2, j)
}
wip := make([]int, len(t2))
// ========= Finish now, we can solve the task ======
t2[1] = 12
t2[2] = 2
ParseArray(t2)
copy(wip, t2)
wip[1] = 12
wip[2] = 2
ParseArray(wip)
log.Println("Part1: " + strconv.Itoa(wip[0]))
log.Println("Part1: " + strconv.Itoa(t2[0]))
noun, verb := Brutforce(t2, 19690720)
if noun == -1 || verb == -1 {
log.Fatal("Part2: No values found!")
}
log.Println("Part2: noun=" + strconv.Itoa(noun) + " verb=" + strconv.Itoa(verb))
}
func Brutforce(list []int, des int) (int, int) {
wip := make([]int, len(list))
copy(wip, list)
for i := 0; i < 100; i++ {
for j := 0; j < 100; j++ {
copy(wip, list)
wip[1] = i
wip[2] = j
ParseArray(wip)
if wip[0] == des {
return i, j
}
}
}
return -1, -1
}
func ParseArray(list []int) error {