✨ Finish part 2 of day 2
This commit is contained in:
parent
1680aec3ad
commit
4f48f24c74
35
day2/main.go
35
day2/main.go
@ -32,12 +32,39 @@ func main() {
|
|||||||
}
|
}
|
||||||
t2 = append(t2, j)
|
t2 = append(t2, j)
|
||||||
}
|
}
|
||||||
|
wip := make([]int, len(t2))
|
||||||
// ========= Finish now, we can solve the task ======
|
// ========= Finish now, we can solve the task ======
|
||||||
t2[1] = 12
|
copy(wip, t2)
|
||||||
t2[2] = 2
|
wip[1] = 12
|
||||||
ParseArray(t2)
|
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 {
|
func ParseArray(list []int) error {
|
||||||
|
Loading…
Reference in New Issue
Block a user