diff --git a/main.go b/main.go index f1978c4..e613d7c 100644 --- a/main.go +++ b/main.go @@ -14,7 +14,7 @@ func main() { runAndBenchmark("02", "2", false, solutions.Day02Part02) runAndBenchmark("03", "1", false, solutions.Day03Part01) - runAndBenchmark("03", "2", true, solutions.Day03Part02) + runAndBenchmark("03", "2", false, solutions.Day03Part02) } type execute func(bool) int @@ -24,5 +24,5 @@ func runAndBenchmark(day, part string, isTest bool, fn execute) { computation := fn(isTest) endMs := time.Now().UnixMicro() duration := endMs - startMs - fmt.Printf("Day %s part %s:\t%10d\t%5d micros.\n", day, part, computation, duration) + fmt.Printf("Day %s part %s:\t%12d\t%5d micros.\n", day, part, computation, duration) } diff --git a/solutions/day03.go b/solutions/day03.go index 0610592..a5045f6 100644 --- a/solutions/day03.go +++ b/solutions/day03.go @@ -2,9 +2,9 @@ package solutions import "strings" -func countTrees(input string, left, down int) int { +func countTrees(input string, right, down int) int { verticalPos := down - horizontalPos := left + horizontalPos := right lines := strings.Split(input, "\n") width := len(lines[0]) treesCount := 0 @@ -17,7 +17,7 @@ func countTrees(input string, left, down int) int { treesCount += 1 } - horizontalPos += left + horizontalPos += right horizontalPos = horizontalPos % width verticalPos += down } @@ -32,5 +32,13 @@ func Day03Part01(isTest bool) int { } func Day03Part02(isTest bool) int { - return -1 + input := ReadInput("03", isTest) + + amount1 := countTrees(input, 1, 1) + amount2 := countTrees(input, 3, 1) + amount3 := countTrees(input, 5, 1) + amount4 := countTrees(input, 7, 1) + amount5 := countTrees(input, 1, 2) + + return amount1 * amount2 * amount3 * amount4 * amount5 }