This commit is contained in:
Karl Spickermann 2021-12-02 21:34:10 +01:00
parent 4a0a7804d5
commit 79b00adf08
3 changed files with 1065 additions and 0 deletions

59
src/day2/day2.go Normal file
View File

@ -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))
}

1000
src/day2/day2Input.txt Normal file

File diff suppressed because it is too large Load Diff

6
src/day2/day2Test.txt Normal file
View File

@ -0,0 +1,6 @@
forward 5
down 5
forward 8
up 3
down 8
forward 2