AoC2020/day3/day3.go
2020-12-05 14:43:34 +01:00

40 lines
679 B
Go

package main
import (
"AoC2020/helper"
"fmt"
"os"
)
func main() {
args := os.Args[1:]
input, err := helper.GetInput(args[0])
if err != nil {
fmt.Println(err)
}
fmt.Println(day3(input, 3, 1))
fmt.Println(day3Part2(input, [][]int{{1, 1}, {3, 1}, {5, 1}, {7, 1}, {1, 2}}))
}
func day3Part2(input []string, slopes [][]int) int {
result := 1
for _, slope := range slopes {
result = result * day3(input, slope[0], slope[1])
}
return result
}
func day3(input []string, right int, down int) int {
count := 0
x := 0
y := 0
for y < len(input) {
if string(input[y][x]) == "#" {
count++
}
x = (x + right) % (len(input[0]))
y = y + down
}
return count
}