Browse Source

Solve 2020/3/2

master
Garrit Franke 3 years ago
parent
commit
3b6dcfd402
  1. 29
      2020/3/main.go

29
2020/3/main.go

@ -46,7 +46,32 @@ func first(lines []string) interface{} {
}
func second(lines []string) interface{} {
result := 0
return result
return traverse(lines, 1, 1) * traverse(lines, 3, 1) * traverse(lines, 5, 1) * traverse(lines, 7, 1) * traverse(lines, 1, 2)
}
func traverse(lines []string, xoff int, yoff int) int {
currentX := 0
numTrees := 0
for i := 0; i < len(lines); i += yoff {
line := lines[i]
if i == 0 {
continue
}
currentX += xoff
objects := strings.Split(line, "")
if currentX >= len(objects) {
currentX %= len(objects)
}
if objects[currentX] == "#" {
numTrees++
}
}
return numTrees
}

Loading…
Cancel
Save