45 lines
822 B
Go
45 lines
822 B
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
h "git.bullercodeworks.com/brian/adventofcode/helpers"
|
|
)
|
|
|
|
func main() {
|
|
inp := h.StdinToStringSlice()
|
|
total := 1
|
|
for _, slope := range []h.Coordinate{
|
|
{X: 1, Y: 1},
|
|
{X: 3, Y: 1},
|
|
{X: 5, Y: 1},
|
|
{X: 7, Y: 1},
|
|
{X: 1, Y: 2},
|
|
} {
|
|
field := h.StringSliceToCoordByteMap(inp)
|
|
val := countTrees(field, slope.X, slope.Y)
|
|
total = total * val
|
|
fmt.Println(slope.X, slope.Y, ":", val, "Trees")
|
|
}
|
|
fmt.Println("Total:", total)
|
|
}
|
|
|
|
func countTrees(field h.CoordByteMap, x, y int) int {
|
|
trees := 0
|
|
pos := h.Coordinate{X: x, Y: y}
|
|
for pos.Y < field.Height {
|
|
if pos.X > field.Width {
|
|
pos.X = pos.X - field.Width - 1
|
|
}
|
|
if field.Get(pos) == '#' {
|
|
trees++
|
|
field.Put(pos, 'X')
|
|
} else {
|
|
field.Put(pos, 'O')
|
|
}
|
|
pos.Y = pos.Y + y
|
|
pos.X = pos.X + x
|
|
}
|
|
return trees
|
|
}
|