-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
31 changed files
with
958 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# generated by Gradle Wrapper | ||
kt/gradlew linguist-generated | ||
kt/gradlew.bat linguist-generated | ||
|
||
# generated by Kotlin/JS | ||
kt/kotlin-js-store/yarn.lock |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
name: Kotlin benchmarks | ||
|
||
on: | ||
workflow_dispatch: | ||
|
||
permissions: | ||
contents: write | ||
|
||
jobs: | ||
get-inputs: | ||
uses: ephemient/aoc2024/.github/workflows/get-inputs.yml@main | ||
secrets: | ||
SESSION: ${{ secrets.SESSION }} | ||
|
||
jmh-visualizer: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- uses: actions/checkout@v4 | ||
with: | ||
repository: jzillmann/jmh-visualizer | ||
- uses: actions/setup-node@v4 | ||
with: | ||
node-version: 18 | ||
cache: npm | ||
- run: npm install | ||
- run: npm run providedZip | ||
env: | ||
NODE_OPTIONS: --openssl-legacy-provider | ||
- uses: actions/upload-artifact@v4 | ||
with: | ||
name: jmh-visualizer | ||
path: jmh-visualizer.zip | ||
|
||
assemble: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- uses: actions/checkout@v4 | ||
- uses: actions/setup-java@v4 | ||
with: | ||
distribution: temurin | ||
java-version: 17 | ||
- uses: gradle/actions/setup-gradle@v4 | ||
- run: ./gradlew assembleBenchmarks | ||
working-directory: kt | ||
|
||
build: | ||
needs: [ assemble, get-inputs ] | ||
runs-on: ubuntu-latest | ||
strategy: | ||
matrix: | ||
target: [ jvm, js, linuxX64 ] | ||
|
||
steps: | ||
- uses: actions/checkout@v4 | ||
- uses: actions/download-artifact@v4 | ||
with: | ||
name: inputs | ||
path: inputs | ||
- uses: actions/setup-java@v4 | ||
with: | ||
distribution: temurin | ||
java-version: 17 | ||
- uses: gradle/actions/setup-gradle@v4 | ||
with: | ||
cache-read-only: true | ||
- run: ./gradlew ${{ matrix.target }}Benchmark | ||
working-directory: kt | ||
env: | ||
AOC2024_DATADIR: ${{ github.workspace }}/inputs | ||
- uses: actions/upload-artifact@v4 | ||
with: | ||
name: ${{ matrix.target }}-benchmarks | ||
path: kt/aoc2024-exe/build/reports/benchmarks | ||
|
||
docs: | ||
needs: [ jmh-visualizer, build ] | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- uses: actions/checkout@v4 | ||
with: | ||
ref: gh-docs | ||
- uses: actions/download-artifact@v4 | ||
with: | ||
name: jmh-visualizer | ||
- uses: actions/download-artifact@v4 | ||
with: | ||
name: jvm-benchmarks | ||
path: benchmarks | ||
- uses: actions/download-artifact@v4 | ||
with: | ||
name: js-benchmarks | ||
path: benchmarks | ||
- uses: actions/download-artifact@v4 | ||
with: | ||
name: linuxX64-benchmarks | ||
path: benchmarks | ||
- run: rm -rf jmh-visualizer | ||
- run: unzip -d jmh-visualizer jmh-visualizer.zip | ||
- name: Create provided.js | ||
run: | | ||
shopt -s failglob | ||
names=() jsonargs=() | ||
for file in benchmarks/main/*/*.json; do | ||
name=${file##*/} | ||
name=${name%.*} | ||
names+=("$name") | ||
jsonargs+=(--slurpfile "$name" "$file") | ||
done | ||
cat >jmh-visualizer/provided.js <<EOF | ||
// provided.js - generated by ${{ github.repository }}/${{ github.workflow }}, $(date +'%Y-%m-%d %H:%M:%S.%N') | ||
var providedBenchmarks = $(jq --null-input --compact-output '$ARGS.positional|unique' --args "${names[@]}"); | ||
var providedBenchmarkStore = $(jq --null-input '$ARGS.named|map_values(.[0]|sort_by(.benchmark|[split("[.]|(?<!\\d)(?!\\D)|(?<!\\D)(?!\\d)")|map(try tonumber catch .),.]))' "${jsonargs[@]}"); | ||
EOF | ||
- uses: EndBug/add-and-commit@v9 | ||
with: | ||
add: jmh-visualizer | ||
message: 'kotlinx.benchmark ${{ github.sha }}' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
name: Kotlin CI | ||
|
||
on: | ||
push: | ||
branches: [ main ] | ||
paths: [ kt/** ] | ||
pull_request: | ||
branches: [ main ] | ||
paths: [ kt/** ] | ||
|
||
workflow_dispatch: | ||
|
||
jobs: | ||
get-inputs: | ||
uses: ephemient/aoc2024/.github/workflows/get-inputs.yml@main | ||
secrets: | ||
SESSION: ${{ secrets.SESSION }} | ||
|
||
build: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- uses: actions/checkout@v4 | ||
- uses: actions/setup-java@v4 | ||
with: | ||
distribution: temurin | ||
java-version: 17 | ||
- uses: gradle/actions/setup-gradle@v4 | ||
- run: ./gradlew build distZip | ||
working-directory: kt | ||
- uses: actions/upload-artifact@v4 | ||
with: | ||
name: aoc2024-exe | ||
path: kt/aoc2024-exe/build/distributions/*.zip | ||
- uses: actions/upload-artifact@v4 | ||
with: | ||
name: aoc2024-kexe | ||
path: | | ||
kt/aoc2024-exe/build/bin/*/debugExecutable/*.kexe | ||
kt/aoc2024-exe/build/bin/*/releaseExecutable/*.kexe | ||
- uses: actions/upload-artifact@v4 | ||
with: | ||
name: aoc2024-js | ||
path: kt/build/js/packages/aoc2024-aoc2024-exe/kotlin/* | ||
- uses: actions/upload-artifact@v4 | ||
with: | ||
name: aoc2024-web | ||
path: kt/web/build/dist/js/productionExecutable/* | ||
|
||
run-jvm: | ||
needs: [ get-inputs, build ] | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- uses: actions/download-artifact@v4 | ||
with: | ||
name: inputs | ||
path: inputs | ||
- uses: actions/download-artifact@v4 | ||
with: | ||
name: aoc2024-exe | ||
- run: unzip aoc2024-exe.zip | ||
- uses: actions/setup-java@v4 | ||
with: | ||
distribution: temurin | ||
java-version: 17 | ||
- run: aoc2024-exe/bin/aoc2024-exe | ||
env: | ||
AOC2024_DATADIR: inputs | ||
|
||
run-native: | ||
needs: [ get-inputs, build ] | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- uses: actions/download-artifact@v4 | ||
with: | ||
name: inputs | ||
path: inputs | ||
- uses: actions/download-artifact@v4 | ||
with: | ||
name: aoc2024-kexe | ||
- run: chmod +x linuxX64/*/aoc2024-exe.kexe | ||
- run: linuxX64/releaseExecutable/aoc2024-exe.kexe | ||
env: | ||
AOC2024_DATADIR: inputs | ||
|
||
run-node: | ||
needs: [ get-inputs, build ] | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- uses: actions/download-artifact@v4 | ||
with: | ||
name: inputs | ||
path: inputs | ||
- uses: actions/download-artifact@v4 | ||
with: | ||
name: aoc2024-js | ||
- uses: actions/setup-node@v4 | ||
with: | ||
node-version: 22.0.0 | ||
- run: node aoc2024-aoc2024-exe.js | ||
env: | ||
AOC2024_DATADIR: inputs |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export AOC2024_DATADIR=$(realpath ..) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
.gradle/ | ||
.kotlin/ | ||
.idea/ | ||
build/ | ||
local.properties | ||
*~ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# [Advent of Code 2024](https://adventofcode.com/2024) | ||
### my answers in [Kotlin](https://www.kotlinlang.org/) ![Kotlin CI](https://github.com/ephemient/aoc2024/workflows/Kotlin%20CI/badge.svg) | ||
|
||
This project builds with [Gradle](https://gradle.org/). | ||
|
||
Run the test suite: | ||
|
||
```sh | ||
./gradlew :aoc2024-lib:allTests | ||
``` | ||
|
||
Print solutions for the inputs provided in local data files: | ||
|
||
```sh | ||
./gradlew :aoc2024-exe:jvmRun | ||
``` | ||
|
||
Run all checks, including [Detekt](https://detekt.github.io/) static code analysis: | ||
|
||
```sh | ||
./gradlew check | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import io.gitlab.arturbosch.detekt.Detekt | ||
|
||
plugins { | ||
alias(libs.plugins.kotlin.multiplatform) | ||
alias(libs.plugins.detekt) | ||
} | ||
|
||
kotlin { | ||
jvm { | ||
mainRun { | ||
mainClass = "com.github.ephemient.aoc2024.exe.Main" | ||
} | ||
} | ||
|
||
sourceSets { | ||
commonMain { | ||
dependencies { | ||
implementation(projects.aoc2024Lib) | ||
implementation(libs.kotlinx.coroutines) | ||
} | ||
} | ||
} | ||
} | ||
|
||
dependencies { | ||
detektPlugins(libs.bundles.detekt.plugins) | ||
} |
12 changes: 12 additions & 0 deletions
12
kt/aoc2024-exe/src/commonMain/kotlin/com/github/ephemient/aoc2024/exe/CommonMain.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package com.github.ephemient.aoc2024.exe | ||
|
||
import com.github.ephemient.aoc2024.days | ||
|
||
internal suspend fun mainImpl(args: Array<out String>) { | ||
for (day in days) { | ||
if ((args.isNotEmpty() || day.skipByDefault) && day.name !in args) continue | ||
println("Day ${day.name}") | ||
for (part in day.solver(getDayInput(day.day))) println(part()) | ||
println() | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
kt/aoc2024-exe/src/commonMain/kotlin/com/github/ephemient/aoc2024/exe/IO.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
package com.github.ephemient.aoc2024.exe | ||
|
||
internal expect fun getDayInput(day: Int): String |
6 changes: 6 additions & 0 deletions
6
kt/aoc2024-exe/src/jvmMain/kotlin/com/github/ephemient/aoc2024/exe/IO.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package com.github.ephemient.aoc2024.exe | ||
|
||
import java.io.File | ||
|
||
internal actual fun getDayInput(day: Int): String = | ||
File(System.getenv("AOC2024_DATADIR")?.ifEmpty { null } ?: ".", "day$day.txt").readText() |
11 changes: 11 additions & 0 deletions
11
kt/aoc2024-exe/src/jvmMain/kotlin/com/github/ephemient/aoc2024/exe/JvmMain.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
@file:JvmName("Main") | ||
|
||
package com.github.ephemient.aoc2024.exe | ||
|
||
import kotlinx.coroutines.Dispatchers | ||
import kotlinx.coroutines.withContext | ||
|
||
@Suppress("InjectDispatcher") | ||
suspend fun main(vararg args: String): Unit = withContext(Dispatchers.Default) { | ||
mainImpl(args) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
plugins { | ||
alias(libs.plugins.kotlin.multiplatform) | ||
alias(libs.plugins.detekt) | ||
} | ||
|
||
kotlin { | ||
jvm() | ||
|
||
sourceSets { | ||
commonMain { | ||
dependencies { | ||
implementation(libs.kotlinx.coroutines) | ||
} | ||
} | ||
|
||
commonTest { | ||
dependencies { | ||
implementation(kotlin("test")) | ||
implementation(libs.kotlinx.coroutines.test) | ||
} | ||
} | ||
|
||
jvmTest { | ||
dependencies { | ||
implementation(kotlin("test-junit5")) | ||
implementation(libs.junit.jupiter.api) | ||
runtimeOnly(libs.junit.jupiter.engine) | ||
} | ||
} | ||
} | ||
} | ||
|
||
dependencies { | ||
detektPlugins(libs.bundles.detekt.plugins) | ||
} | ||
|
||
tasks.withType<Test>().configureEach { | ||
useJUnitPlatform() | ||
} |
Oops, something went wrong.