advent-of-code-2021/2/part1.go

32 lines
430 B
Go
Raw Permalink Normal View History

2021-12-04 06:24:29 +00:00
package main
import (
"bufio"
"fmt"
"os"
"strconv"
"strings"
)
func main() {
depth := 0
position := 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
case "up":
depth -= value
case "down":
depth += value
}
}
fmt.Println(depth * position)
}