2021 Day 1 Complete!

This commit is contained in:
Brian Buller 2021-12-01 08:02:57 -06:00
parent 49a625c6e6
commit 937713f2a5
3 changed files with 2049 additions and 0 deletions

2000
2021/day01/input Normal file

File diff suppressed because it is too large Load Diff

39
2021/day01/main.go Normal file
View File

@ -0,0 +1,39 @@
package main
import (
"fmt"
h "git.bullercodeworks.com/brian/adventofcode/helpers"
)
func main() {
inp := h.StdinToIntSlice()
fmt.Println("# Part 1")
part1(inp)
fmt.Println("# Part 2")
part2(inp)
}
func part1(input []int) {
var inc int
for i := 1; i < len(input); i++ {
if input[i] > input[i-1] {
inc++
}
}
fmt.Printf("%d measurements increased\n", inc)
}
func part2(input []int) {
var inc int
for i := 1; i < len(input); i++ {
if i < len(input)-2 {
a := input[i-1] + input[i] + input[i+1]
b := input[i] + input[i+1] + input[i+2]
if b > a {
inc++
}
}
}
fmt.Printf("%d measurement windows increased\n", inc)
}

10
2021/day01/testinput Normal file
View File

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