-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathday03.go
47 lines (36 loc) · 997 Bytes
/
day03.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
package main
import (
"fmt"
"io/ioutil"
)
func CheckTreesWithSlope(data []string, dx int, dy int) int {
x, y := 0, 0
trees := 0
for y+dy < len(data) {
x = (x + dx) % len(data[0])
y += dy
spot := string(data[y][x])
if spot == "#" {
trees++
}
}
return trees
}
// Starting at the top-left corner of your map
// and following a slope of right 3 and down 1,
// how many trees would you encounter
func day03() {
inp, _ := ioutil.ReadFile("./inputs/day03.input")
data := GetStringInput(inp)
slope11 := CheckTreesWithSlope(data, 1, 1)
slope31 := CheckTreesWithSlope(data, 3, 1)
slope51 := CheckTreesWithSlope(data, 5, 1)
slope71 := CheckTreesWithSlope(data, 7, 1)
slope12 := CheckTreesWithSlope(data, 1, 2)
fmt.Println("1x1", slope11)
fmt.Println("3x1", slope31)
fmt.Println("5x1", slope51)
fmt.Println("7x1", slope71)
fmt.Println("1x2", slope12)
fmt.Println("together", slope11*slope12*slope31*slope51*slope71)
}