-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
69 lines (57 loc) · 1.05 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package main
import (
"fmt"
"github.com/davidporos92/aoc-2020/utils"
)
const tree = "#"
type Slope struct {
moveRight int
moveDown int
treeCount int
}
var slopes = []Slope{
{
moveRight: 1,
moveDown: 1,
},
{
moveRight: 3,
moveDown: 1,
},
{
moveRight: 5,
moveDown: 1,
},
{
moveRight: 7,
moveDown: 1,
},
{
moveRight: 1,
moveDown: 2,
},
}
func main() {
treeMultiplication := 1
myMap := utils.NewReader("./input-1.dat").MustReadStringMapFromFile()
for _, slope := range slopes {
currentPositionX := 0
currentPositionY := 0
for {
if myMap[currentPositionY][currentPositionX] == tree {
slope.treeCount++
}
currentPositionX += slope.moveRight
currentPositionY += slope.moveDown
if currentPositionY >= len(myMap) {
break
}
if currentPositionX >= len(myMap[currentPositionY]) {
currentPositionX -= len(myMap[currentPositionY])
}
}
fmt.Printf("Tree count for slope: %+v\n", slope)
treeMultiplication *= slope.treeCount
}
fmt.Printf("Tree multiplication: %d\n", treeMultiplication)
}