package main import ( "fmt" "os" "git.annabunch.es/annabunches/adventofcode/2020/lib/util" ) 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 := util.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) } }