File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ package main
2+
3+ import (
4+ "fmt"
5+ "strconv"
6+ "strings"
7+
8+ "github.com/markkovari/advent_of_code/aoc-go-common"
9+ )
10+
11+ type Day05 struct {}
12+
13+ func (d Day05 ) Part1 (input string ) string {
14+ jumps := parse (input )
15+ current , steps := 0 , 0
16+ for current >= 0 && current < len (jumps ) {
17+ jump := jumps [current ]
18+ jumps [current ]++
19+ current += jump
20+ steps ++
21+ }
22+ return fmt .Sprintf ("%d" , steps )
23+ }
24+
25+ func (d Day05 ) Part2 (input string ) string {
26+ jumps := parse (input )
27+ current , steps := 0 , 0
28+ for current >= 0 && current < len (jumps ) {
29+ jump := jumps [current ]
30+ if jump >= 3 {
31+ jumps [current ]--
32+ } else {
33+ jumps [current ]++
34+ }
35+ current += jump
36+ steps ++
37+ }
38+ return fmt .Sprintf ("%d" , steps )
39+ }
40+
41+ func parse (input string ) []int {
42+ var nums []int
43+ for _ , line := range strings .Split (input , "\n " ) {
44+ if line == "" { continue }
45+ val , _ := strconv .Atoi (line )
46+ nums = append (nums , val )
47+ }
48+ return nums
49+ }
50+
51+ func main () {
52+ common .Run (2017 , 5 , Day05 {})
53+ }
You can’t perform that action at this time.
0 commit comments