Skip to content

Commit 0f12f09

Browse files
committed
Add all the things so far -- not motivated to make it pretty :P
0 parents  commit 0f12f09

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+9540
-0
lines changed

01/example.txt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
1000
2+
2000
3+
3000
4+
5+
4000
6+
7+
5000
8+
6000
9+
10+
7000
11+
8000
12+
9000
13+
14+
10000

01/main.go

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
"sort"
6+
"strconv"
7+
8+
"github.com/vimkat/aoc-2022/util"
9+
)
10+
11+
func main() {
12+
c := caloriesPerElve("puzzle.txt")
13+
sort.Sort(sort.Reverse(sort.IntSlice(c)))
14+
fmt.Println(c[0])
15+
fmt.Println(util.Sum(c[0:3]))
16+
}
17+
18+
func caloriesPerElve(path string) []int {
19+
calories := []int{0}
20+
elf := 0
21+
22+
for line := range util.ReadByLines(path) {
23+
if line == "" {
24+
elf++
25+
calories = append(calories, 0)
26+
} else {
27+
i, err := strconv.Atoi(line)
28+
util.Must(err)
29+
calories[elf] += i
30+
}
31+
}
32+
33+
return calories
34+
}

0 commit comments

Comments
 (0)