Day2
This commit is contained in:
parent
4a0a7804d5
commit
79b00adf08
|
@ -0,0 +1,59 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"AOC2021/src/helper"
|
||||
"fmt"
|
||||
"os"
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func main() {
|
||||
args := os.Args[1:]
|
||||
input, err := helper.GetInput(args[0])
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
}
|
||||
//part1(input)
|
||||
part2(input)
|
||||
}
|
||||
|
||||
func part2(input []string) {
|
||||
forward := 0
|
||||
depth := 0
|
||||
aim := 0
|
||||
for _, line := range input {
|
||||
seperatedLine := strings.Fields(line)
|
||||
movement := seperatedLine[0]
|
||||
distance, _ := strconv.Atoi(seperatedLine[1])
|
||||
switch movement {
|
||||
case "forward":
|
||||
forward += distance
|
||||
depth += aim * distance
|
||||
case "down":
|
||||
aim += distance
|
||||
case "up":
|
||||
aim -= distance
|
||||
}
|
||||
}
|
||||
fmt.Printf("With a forward of %d and depth of %d I get the value %d \r\n", forward, depth, (forward * depth))
|
||||
}
|
||||
|
||||
func part1(input []string) {
|
||||
forward := 0
|
||||
depth := 0
|
||||
for _, line := range input {
|
||||
seperatedLine := strings.Fields(line)
|
||||
movement := seperatedLine[0]
|
||||
distance, _ := strconv.Atoi(seperatedLine[1])
|
||||
switch movement {
|
||||
case "forward":
|
||||
forward += distance
|
||||
case "down":
|
||||
depth += distance
|
||||
case "up":
|
||||
depth -= distance
|
||||
}
|
||||
}
|
||||
fmt.Printf("With a forward of %d and depth of %d I get the value %d \r\n", forward, depth, (forward * depth))
|
||||
}
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,6 @@
|
|||
forward 5
|
||||
down 5
|
||||
forward 8
|
||||
up 3
|
||||
down 8
|
||||
forward 2
|
Loading…
Reference in New Issue
Block a user