File tree Expand file tree Collapse file tree 19 files changed +87
-135
lines changed
Expand file tree Collapse file tree 19 files changed +87
-135
lines changed Original file line number Diff line number Diff line change 1+ // Advent of Code 2024
2+ // By Sebastian Raaphorst, 2024.
3+
14package common.aocreader
25
36import java.net.HttpURLConnection
Original file line number Diff line number Diff line change 1- // Advent of Code
1+ // Advent of Code 2024
22// By Sebastian Raaphorst, 2024.
33
44package common.collectionops
Load Diff This file was deleted.
Original file line number Diff line number Diff line change 1+ // Advent of Code 2024
2+ // By Sebastian Raaphorst, 2024.
3+
14package common.intpos2d
25
36typealias IntPos2D = Pair <Int , Int >
Original file line number Diff line number Diff line change 1- // Advent of Code
1+ // Advent of Code 2024
22// By Sebastian Raaphorst, 2024.
33
44package common.parsing
Original file line number Diff line number Diff line change 1+ // Advent of Code 2024
2+ // By Sebastian Raaphorst, 2024.
3+
4+ package common.runner
5+
6+ inline fun <T > timedFunction (functionName : String , block : () -> T ): T {
7+ val startTime = System .nanoTime()
8+ val result = block()
9+ val endTime = System .nanoTime()
10+ println (" $functionName : $result (${(endTime - startTime) / 1_000_000.0 } ms)" )
11+ return result
12+ }
Original file line number Diff line number Diff line change 1- // Advent of Code
1+ // Advent of Code 2024
22// By Sebastian Raaphorst, 2024.
33
44package common
Original file line number Diff line number Diff line change @@ -6,6 +6,7 @@ package day01
66import common.aocreader.fetchAdventOfCodeInput
77import common.parsing.parseColumns
88import common.collectionops.toFrequencyMap
9+ import common.runner.timedFunction
910import kotlin.math.abs
1011
1112fun answer1 (input : String ): Int =
@@ -25,12 +26,7 @@ fun answer2(input: String): Int =
2526
2627fun main () {
2728 val input = fetchAdventOfCodeInput(2024 , 1 )
28-
2929 println (" --- Day 1: Historian Hysteria ---" )
30-
31- // Answer 1: 2031679
32- println (" Part 1: ${answer1(input)} " )
33-
34- // Answer 2: 19678534
35- println (" Part 2: ${answer2(input)} " )
30+ timedFunction(" Part 1" ) { answer1(input) } // 2031679
31+ timedFunction(" Part 2" ) { answer2(input) } // 19678534
3632}
Original file line number Diff line number Diff line change @@ -6,6 +6,7 @@ package day02
66import common.aocreader.fetchAdventOfCodeInput
77import common.collectionops.allListDrops
88import common.parsing.parseGrid
9+ import common.runner.timedFunction
910
1011private const val Lower = 1
1112private const val Upper = 3
@@ -30,12 +31,7 @@ fun answer2(input: String): Int =
3031
3132fun main () {
3233 val input = fetchAdventOfCodeInput(2024 , 2 )
33-
3434 println (" --- Day 2: Red-Nosed Reports ---" )
35-
36- // Answer 1: 379
37- println (" Part 1: ${answer1(input)} " )
38-
39- // Answer 2: 430
40- println (" Part 2: ${answer2(input)} " )
35+ timedFunction(" Part 1" ) { answer1(input) } // 379
36+ timedFunction(" Part 2" ) { answer2(input) } // 430
4137}
Original file line number Diff line number Diff line change 44package day03
55
66import common.aocreader.fetchAdventOfCodeInput
7+ import common.runner.timedFunction
78
89/* *
910 * We want to turn off processing for substrings of the form:
@@ -31,12 +32,7 @@ fun answer2(input: String): Int =
3132
3233fun main () {
3334 val input = fetchAdventOfCodeInput(2024 , 3 )
34-
3535 println (" --- Day 3: Mull It Over ---" )
36-
37- // Answer 1: 173785482
38- println (" Part 1: ${answer1(input)} " )
39-
40- // Answer 2: 83158140
41- println (" Part 2: ${answer2(input)} " )
36+ timedFunction(" Part 1" ) { answer1(input) } // 173785482
37+ timedFunction(" Part 2" ) { answer2(input) } // 83158140
4238}
You can’t perform that action at this time.
0 commit comments