-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexercise.go
61 lines (46 loc) · 1.11 KB
/
exercise.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package exercises
import (
"github.com/asphaltbuffet/advent-of-code/internal/common"
)
// Exercise for Advent of Code 2022 day 20.
type Exercise struct {
common.BaseExercise
}
// One returns the answer to the first part of the exercise.
// wrong: 9476 (too high)
// answer: 4066
func (e Exercise) One(instr string) (any, error) {
f, err := parse(instr, 1)
if err != nil {
return nil, err
}
f.decrypted.Do(func(v digit) {
println(v.value)
})
err = f.decrypt()
if err != nil {
return nil, err
}
// fmt.Println(f.decryptedToString())
c1, c2, c3 := f.getCoordinates()
// fmt.Printf("coordinates = %d %d %d\n", c1, c2, c3)
return c1 + c2 + c3, nil
}
// Two returns the answer to the second part of the exercise.
// answer: 6704537992933
func (e Exercise) Two(instr string) (any, error) {
f, err := parse(instr, 811589153)
if err != nil {
return nil, err
}
for i := 0; i < 10; i++ {
err = f.decrypt()
if err != nil {
return nil, err
}
}
// fmt.Println(f.decryptedToString())
c1, c2, c3 := f.getCoordinates()
// fmt.Printf("coordinates = %d %d %d\n", c1, c2, c3)
return c1 + c2 + c3, nil
}