2021 Day 1 Complete!
This commit is contained in:
parent
49a625c6e6
commit
937713f2a5
2000
2021/day01/input
Normal file
2000
2021/day01/input
Normal file
File diff suppressed because it is too large
Load Diff
39
2021/day01/main.go
Normal file
39
2021/day01/main.go
Normal 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
10
2021/day01/testinput
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
199
|
||||||
|
200
|
||||||
|
208
|
||||||
|
210
|
||||||
|
200
|
||||||
|
207
|
||||||
|
240
|
||||||
|
269
|
||||||
|
260
|
||||||
|
263
|
Loading…
Reference in New Issue
Block a user