Started AOC 2020 - solved the first 4.5 days.
This commit is contained in:
parent
bab5f879b0
commit
04f29cdb4d
9 changed files with 389 additions and 0 deletions
44
2020/day03.go
Normal file
44
2020/day03.go
Normal file
|
@ -0,0 +1,44 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"git.annabunch.es/annabunches/adventofcode/2020/lib/fileutils"
|
||||
)
|
||||
|
||||
func countTrees(input []string, right, down int) int {
|
||||
x := 0
|
||||
total := 0
|
||||
for y, line := range input {
|
||||
if y == 0 || len(line) == 0 || y%down != 0 {
|
||||
continue
|
||||
}
|
||||
|
||||
x = (x + right) % len(line)
|
||||
if line[x] == '#' {
|
||||
total += 1
|
||||
}
|
||||
}
|
||||
|
||||
return total
|
||||
}
|
||||
|
||||
func main() {
|
||||
step := os.Args[1]
|
||||
values := fileutils.InputParserStrings(os.Args[2])
|
||||
|
||||
switch step {
|
||||
case "1":
|
||||
total := countTrees(values, 3, 1)
|
||||
fmt.Println("Trees:", total)
|
||||
case "2":
|
||||
total := countTrees(values, 1, 1)
|
||||
total *= countTrees(values, 3, 1)
|
||||
total *= countTrees(values, 5, 1)
|
||||
total *= countTrees(values, 7, 1)
|
||||
total *= countTrees(values, 1, 2)
|
||||
fmt.Println("Tree Product:", total)
|
||||
}
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue