You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
aoc2020/day03/lib.go

20 lines
373 B

package day03
func checkSlope(rows [][]byte, ySpeed int, xSpeed int) int {
rowLen := len(rows[0])
key := 0
counter := 0
for i := 0; i < len(rows); i += ySpeed {
// Check if this column on this row is a tree ASCII Char 35 (#)
// Use modulo to "wrap" the map.
if rows[i][key%rowLen] == 35 {
counter++
}
// Step right
key += xSpeed
}
return counter
}