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