-
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
8 changed files
with
1,003 additions
and
21 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
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
Large diffs are not rendered by default.
Oops, something went wrong.
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,32 @@ | ||
plugins { | ||
kotlin("multiplatform") | ||
id("com.github.ephemient.aoc2023.kotlin.multiplatform.js.platform") | ||
} | ||
|
||
kotlin { | ||
js { | ||
useCommonJs() | ||
browser { | ||
commonWebpackConfig { | ||
outputFileName = "script.js" | ||
} | ||
} | ||
binaries.executable() | ||
} | ||
|
||
sourceSets { | ||
commonMain { | ||
dependencies { | ||
implementation(projects.aoc2023Lib) | ||
implementation(libs.kotlinx.coroutines) | ||
} | ||
} | ||
|
||
jsMain { | ||
dependencies { | ||
implementation(libs.kotlin.wrappers.browser) | ||
implementation(libs.kotlinx.html) | ||
} | ||
} | ||
} | ||
} |
46 changes: 46 additions & 0 deletions
46
kt/web/src/jsMain/kotlin/com/github/ephemient/aoc2023/web/Main.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,46 @@ | ||
package com.github.ephemient.aoc2023.web | ||
|
||
import com.github.ephemient.aoc2023.days | ||
import kotlinx.browser.document | ||
import kotlinx.coroutines.GlobalScope | ||
import kotlinx.coroutines.SupervisorJob | ||
import kotlinx.coroutines.async | ||
import kotlinx.coroutines.cancelChildren | ||
import kotlinx.coroutines.launch | ||
import kotlinx.dom.appendText | ||
import kotlinx.dom.clear | ||
import kotlinx.html.dom.append | ||
import kotlinx.html.js.option | ||
import org.w3c.dom.HTMLFormElement | ||
import org.w3c.dom.HTMLPreElement | ||
import org.w3c.dom.HTMLSelectElement | ||
import org.w3c.dom.HTMLTextAreaElement | ||
|
||
fun main() { | ||
val daySelect = document.getElementById("day") as HTMLSelectElement | ||
val input = document.getElementById("input") as HTMLTextAreaElement | ||
val output = document.getElementById("output") as HTMLPreElement | ||
val form = document.getElementById("container") as HTMLFormElement | ||
daySelect.append { | ||
for ((i, day) in days.withIndex()) { | ||
option { | ||
value = i.toString() | ||
+"Day ${day.name}" | ||
} | ||
} | ||
} | ||
val job = SupervisorJob() | ||
form.onsubmit = { event -> | ||
val day = days[daySelect.value.toInt()] | ||
job.cancelChildren() | ||
output.clear() | ||
GlobalScope.launch(job) { | ||
val parts = day.solver(input.value).map { async { it() } } | ||
for (part in parts) { | ||
val result = part.await() | ||
output.appendText("$result\n") | ||
} | ||
} | ||
event.preventDefault() | ||
} | ||
} |
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,15 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<title>Advent of Code 2023 in Kotlin/JS by @ephemient</title> | ||
</head> | ||
<body> | ||
<form id="container"> | ||
<select id="day"></select> | ||
<textarea id="input"></textarea> | ||
<pre id="output"></pre> | ||
<input type="submit"> | ||
</form> | ||
<script src="script.js"></script> | ||
</body> | ||
</html> |