Day 3 part 1
This commit is contained in:
parent
93c256d989
commit
bcce0722fb
7
main.go
7
main.go
@ -10,8 +10,11 @@ func main() {
|
||||
runAndBenchmark("01", "1", false, solutions.Day01Part01)
|
||||
runAndBenchmark("01", "2", false, solutions.Day01Part02)
|
||||
|
||||
runAndBenchmark("02", "1", false, solutions.Day01Part01)
|
||||
runAndBenchmark("02", "2", false, solutions.Day01Part02)
|
||||
runAndBenchmark("02", "1", false, solutions.Day02Part01)
|
||||
runAndBenchmark("02", "2", false, solutions.Day02Part02)
|
||||
|
||||
runAndBenchmark("03", "1", false, solutions.Day03Part01)
|
||||
runAndBenchmark("03", "2", true, solutions.Day03Part02)
|
||||
}
|
||||
|
||||
type execute func(bool) int
|
||||
|
36
solutions/day03.go
Normal file
36
solutions/day03.go
Normal file
@ -0,0 +1,36 @@
|
||||
package solutions
|
||||
|
||||
import "strings"
|
||||
|
||||
func countTrees(input string, left, down int) int {
|
||||
verticalPos := down
|
||||
horizontalPos := left
|
||||
lines := strings.Split(input, "\n")
|
||||
width := len(lines[0])
|
||||
treesCount := 0
|
||||
|
||||
for verticalPos < len(lines) {
|
||||
line := lines[verticalPos]
|
||||
charAt := string(line[horizontalPos])
|
||||
|
||||
if charAt == "#" {
|
||||
treesCount += 1
|
||||
}
|
||||
|
||||
horizontalPos += left
|
||||
horizontalPos = horizontalPos % width
|
||||
verticalPos += down
|
||||
}
|
||||
|
||||
return treesCount
|
||||
}
|
||||
|
||||
func Day03Part01(isTest bool) int {
|
||||
input := ReadInput("03", isTest)
|
||||
|
||||
return countTrees(input, 3, 1)
|
||||
}
|
||||
|
||||
func Day03Part02(isTest bool) int {
|
||||
return -1
|
||||
}
|
Loading…
Reference in New Issue
Block a user