-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
60 lines (51 loc) · 1.09 KB
/
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package main
import (
"fmt"
"log"
"github.com/williamgcampbell/aoc2022/internal/days"
)
const (
chorus = "On the %s day of Christmas the part %s solution is: %s\n"
numDays = 25
)
func main() {
r := days.NewDayRegistry()
days.RegisterAll(r)
for i := 1; i <= numDays; i++ {
if day, ok := r[i]; ok {
singDay(i, day)
} else {
log.Fatalf("Could not find day %d", i)
}
}
}
func singDay(num int, day days.Solver) {
singPart("one", num, day.SolvePart1())
singPart("two", num, day.SolvePart2())
}
func singPart(part string, day int, solution string) {
if day == 5 && part == "one" {
fmt.Println("FIIIIIIIIIIVE GOOOOOLDEN R....just kidding. ")
}
fmt.Printf(chorus, ordinalString(day), part, normalizeSolution(solution))
}
func normalizeSolution(r string) string {
if r == "" {
return "I don't know"
}
return r
}
func ordinalString(i int) string {
j := i % 10
k := i % 100
if j == 1 && k != 11 {
return fmt.Sprintf("%dst", i)
}
if j == 2 && k != 12 {
return fmt.Sprintf("%dnd", i)
}
if j == 3 && k != 13 {
return fmt.Sprintf("%drd", i)
}
return fmt.Sprintf("%dth", i)
}