34 lines
460 B
Go
34 lines
460 B
Go
|
package main
|
||
|
|
||
|
import (
|
||
|
"bufio"
|
||
|
"fmt"
|
||
|
"os"
|
||
|
"strconv"
|
||
|
"strings"
|
||
|
)
|
||
|
|
||
|
func main() {
|
||
|
depth := 0
|
||
|
position := 0
|
||
|
aim := 0
|
||
|
|
||
|
s := bufio.NewScanner(os.Stdin)
|
||
|
for s.Scan() {
|
||
|
tokens := strings.Split(s.Text(), " ")
|
||
|
direction := tokens[0]
|
||
|
value, _ := strconv.Atoi(tokens[1])
|
||
|
switch direction {
|
||
|
case "forward":
|
||
|
position += value
|
||
|
depth += aim * value
|
||
|
case "up":
|
||
|
aim -= value
|
||
|
case "down":
|
||
|
aim += value
|
||
|
}
|
||
|
}
|
||
|
|
||
|
fmt.Println(depth * position)
|
||
|
}
|