49 lines
838 B
Go
49 lines
838 B
Go
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)
|
|
}
|