master
Karl Spickermann 1 year ago
parent 3c88a4fbdd
commit 4a0a7804d5

@ -0,0 +1,56 @@
package main
import (
"AOC2021/src/helper"
"fmt"
"os"
)
func main() {
args := os.Args[1:]
input, err := helper.GetInput(args[0])
if err != nil {
fmt.Println(err)
}
numbers, err := helper.MapToNumber(input)
if err != nil {
fmt.Println(err)
}
fmt.Println("Part 1")
part1(numbers)
fmt.Println("Part 2")
part2(numbers)
}
func part2(numbers []int) {
fmt.Println(helper.AddNummbers(numbers[0:3]...))
amountOfIncreased := 0
for i := 1; i < len(numbers)-2; i++ {
var change = "decreased"
previousWindow := helper.AddNummbers(numbers[i-1 : i+2]...)
currentWindow := helper.AddNummbers(numbers[i : i+3]...)
if currentWindow > previousWindow {
amountOfIncreased++
change = "increased"
}
if currentWindow == previousWindow {
change = "no change"
}
fmt.Printf("%d (%s) \r\n", currentWindow, change)
}
fmt.Println(amountOfIncreased)
}
func part1(numbers []int) {
amountOfIncreased := 0
for i := 1; i < len(numbers); i++ {
var change = "decreased"
if numbers[i] > numbers[i-1] {
amountOfIncreased++
change = "increased"
}
fmt.Printf("%d (%s) \r\n", numbers[i], change)
}
fmt.Println(amountOfIncreased)
}

File diff suppressed because it is too large Load Diff

@ -0,0 +1,10 @@
199
200
208
210
200
207
240
269
260
263
Loading…
Cancel
Save