-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path5p1.txt
More file actions
58 lines (52 loc) · 762 Bytes
/
5p1.txt
File metadata and controls
58 lines (52 loc) · 762 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
package main
import (
"bufio"
"fmt"
"log"
"os"
"strconv"
)
func makeJumpsList(filepath string) ([]int, error) {
f, err := os.Open(filepath)
if err != nil {
return nil, err
}
defer f.Close()
jumps := []int{}
scanner := bufio.NewScanner(f)
for scanner.Scan() {
s := scanner.Text()
if s == "" {
continue
}
i, err := strconv.Atoi(s)
if err != nil {
return nil, err
}
jumps = append(jumps, i)
}
return jumps, nil
}
func main() {
jumps, err := makeJumpsList("input")
if err != nil {
log.Fatal(err)
}
var (
count = 0
end = len(jumps) - 1
i = 0
offset = 0
)
for i <= end {
offset = jumps[i]
if offset >= 3 {
jumps[i]--
} else {
jumps[i]++
}
i += offset
count++
}
fmt.Println(count)
}