-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
73 lines (55 loc) · 825 Bytes
/
main.go
File metadata and controls
73 lines (55 loc) · 825 Bytes
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
66
67
68
69
70
71
72
73
package main
import (
"bufio"
"fmt"
"io"
"os"
"path"
"strconv"
)
func input() *os.File {
input, err := os.Open(path.Join("2021", "1", "input.txt"))
if err != nil {
panic(err)
}
return input
}
func solve(r io.Reader) {
scanner := bufio.NewScanner(r)
items := make([]int, 3)
which := 0
inc := 0
i := 0
for scanner.Scan() {
row := scanner.Text()
v, err := strconv.ParseInt(row, 10, 32)
vv := int(v)
if err != nil {
panic(err)
}
old := sum(items)
items[which] = vv
which = (which + 1) % len(items)
if i > 2 {
if sum(items) > old {
inc++
}
}
fmt.Println(items)
i++
}
if scanner.Err() != nil {
panic(scanner.Err())
}
fmt.Println(inc)
}
func sum(v []int) int {
var s int
for _, vv := range v {
s += vv
}
return s
}
func main() {
solve(input())
}