-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
65 lines (54 loc) · 1 KB
/
main.go
File metadata and controls
65 lines (54 loc) · 1 KB
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
62
63
64
65
package main
import (
"github.com/danvolchek/AdventOfCode/lib"
"math"
)
func parse(line string) int {
return lib.Atoi(line)
}
func presents(house int) int {
if house == 1 {
return 10
}
total := 0
for i := 1; i <= int(math.Sqrt(float64(house))); i++ {
if house%i == 0 {
total += i * 10
if i != house/i {
total += (house / i) * 10
}
}
}
return total
}
func solve(target int) int {
i := target / 50
for {
result := presents(i)
if result >= target {
return i
}
i += 1
}
}
func main() {
presentsSolver := lib.Solver[int, int]{
ParseF: parse,
SolveF: presents,
}
presentsSolver.Expect("1", 10)
presentsSolver.Expect("2", 30)
presentsSolver.Expect("3", 40)
presentsSolver.Expect("4", 70)
presentsSolver.Expect("5", 60)
presentsSolver.Expect("6", 120)
presentsSolver.Expect("7", 80)
presentsSolver.Expect("8", 150)
presentsSolver.Expect("9", 130)
solver := lib.Solver[int, int]{
ParseF: parse,
SolveF: solve,
}
solver.Expect("100", 6)
solver.Verify(665280)
}