Day 3 part 1

master
Araozu 2024-02-25 16:37:21 -05:00
parent 93c256d989
commit bcce0722fb
2 changed files with 41 additions and 2 deletions

View File

@ -10,8 +10,11 @@ func main() {
runAndBenchmark("01", "1", false, solutions.Day01Part01) runAndBenchmark("01", "1", false, solutions.Day01Part01)
runAndBenchmark("01", "2", false, solutions.Day01Part02) runAndBenchmark("01", "2", false, solutions.Day01Part02)
runAndBenchmark("02", "1", false, solutions.Day01Part01) runAndBenchmark("02", "1", false, solutions.Day02Part01)
runAndBenchmark("02", "2", false, solutions.Day01Part02) runAndBenchmark("02", "2", false, solutions.Day02Part02)
runAndBenchmark("03", "1", false, solutions.Day03Part01)
runAndBenchmark("03", "2", true, solutions.Day03Part02)
} }
type execute func(bool) int type execute func(bool) int

36
solutions/day03.go Normal file
View 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
}