Day 5: maze => 351282
This commit is contained in:
parent
9aff617dfc
commit
d7ff9586ef
5
05dec/input_test
Normal file
5
05dec/input_test
Normal file
@ -0,0 +1,5 @@
|
||||
0
|
||||
3
|
||||
0
|
||||
1
|
||||
-3
|
48
05dec/main.go
Normal file
48
05dec/main.go
Normal file
@ -0,0 +1,48 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
func main() {
|
||||
moves := parseInput()
|
||||
for _, m := range moves {
|
||||
fmt.Print(*m, " ")
|
||||
}
|
||||
fmt.Println()
|
||||
fmt.Println(maze(moves, 0, 0))
|
||||
}
|
||||
|
||||
func parseInput() []*int {
|
||||
var in string
|
||||
moves := []*int{}
|
||||
sc := bufio.NewScanner(os.Stdin)
|
||||
for sc.Scan() {
|
||||
i, err := strconv.Atoi(sc.Text())
|
||||
//fmt.Println(i)
|
||||
if err != nil {
|
||||
log.Fatalln("Invalid input", in)
|
||||
}
|
||||
moves = append(moves, &i)
|
||||
}
|
||||
return moves
|
||||
}
|
||||
|
||||
func maze(moves []*int, pos int, incr int) int {
|
||||
//fmt.Println("Taille", len(moves))
|
||||
//fmt.Println("pos", pos)
|
||||
offset := *moves[pos]
|
||||
//fmt.Println("offset", offset)
|
||||
newpos := pos + offset
|
||||
if newpos >= len(moves) {
|
||||
return incr + 1
|
||||
}
|
||||
offset++
|
||||
moves[pos] = &offset
|
||||
//fmt.Println("Newoffset at ", pos, *moves[pos])
|
||||
return maze(moves, newpos, incr+1)
|
||||
}
|
Loading…
Reference in New Issue
Block a user