Skip to content

Instantly share code, notes, and snippets.

View saidaspen's full-sized avatar

saidaspen

  • Stockholm, Sweden
View GitHub Profile
@saidaspen
saidaspen / Day12.kt
Last active December 12, 2022 06:18
AOC 2022 12
import se.saidaspen.aoc.util.*
fun main() = Day12.run()
object Day12 : Day(2022, 12) {
private val map = toMap(input)
private fun costOf(b: Pair<Int, Int>, a: Pair<Int, Int>) = (map[b]!!.code - 'a'.code) - (map[a]!!.code - 'a'.code)
private val startPos = map.entries.first { it.value == 'S' }.key
private val endPos = map.entries.first { it.value == 'E' }.key
@saidaspen
saidaspen / aoc202209.kt
Created December 9, 2022 05:58
AoC 2022 Day 09
import se.saidaspen.aoc.util.*
import kotlin.math.absoluteValue
fun main() = Day09.run()
object Day09 : Day(2022, 9) {
override fun part1(): Any {
var h = P(0, 0)
var t = P(0, 0)
@saidaspen
saidaspen / aoc.css
Last active May 20, 2023 21:23
AoC CSS
input ~ span:before,
.leaderboard-entry,
.privboard-row {
font-family: "Source Code Pro", monospace;
letter-spacing: 1px;
}
body * {
text-shadow: none !important;
}
@saidaspen
saidaspen / VMPlayoffSimulator.kt
Created November 15, 2021 22:25
VM Playoff Simulator
import java.text.DecimalFormat
val seeded = listOf("Portugal", "Ryssland", "Schweiz", "Sverige", "Polen", "Wales")
val notSeeded = listOf("Skottland", "Nordmakedonien", "Turkiet", "Finland", "Tjeckien", "Österrike")
val fifaPoints = seeded.zip(listOf(1681.73, 1497.45, 1633.8, 1618.69, 1542.2, 1566.77))
.union(notSeeded.zip(listOf(1451.37, 1343.19, 1460.53, 1403.96, 1503.23, 1501.09))).toMap()
const val ANSI_YELLOW = "\u001B[33m"
const val ANSI_RESET = "\u001B[0m"
private const val HOME_FIELD_ADV = 10.0
@saidaspen
saidaspen / dialinglock.md
Last active January 26, 2021 14:44
Broken Dial Combination Safe

You are in a locked room. A cell? A box, of some sort? Walls, ceiling and floor are all the same worn industrial metal. There is a small door, but it seems secured with some old kind of mechanism. One of those old safebox locks where you spin a knob alternatively left and right to get to the right sequence. "Who puts the lock on the inside of a cell?" you ponder. "It doesn't matter. I need to get out of here."
There are scribblings and scratching on the walls and on the floor. Mainly in one of the corners, the corner where you found yourself sitting just a while ago. Only one thing stands out; a long series of letters, your puzzle inputs.

As you examine the lock's mechanism, it is clear to you that it is ancient. It is covered by corrosion, and its dial only seems to go in one direction, to your right. Something in the lock seems broken, or loose inside of it, as there seem to be something stopping it from rotating to your left. The face of the dial has numbers on it, labelled 1 through 9.

@saidaspen
saidaspen / aoc202day09.kt
Created December 9, 2020 06:02
Advent of Code 2020 Day 9
fun part1(): Long {
val prevFive = ArrayDeque<Long>()
prevFive.addAll(input.subList(0, 25))
for (i in 25 until input.size) {
val elem = input[i]
if (!prevFive.any { prevFive.contains(elem - it) }) return elem
prevFive.removeFirst()
prevFive.addLast(elem)
}
return -1
@saidaspen
saidaspen / main.rs
Created September 18, 2020 21:06
Type annotation?
#[post("/new")]
async fn new(req_body: String) -> impl Responder {
match serde_json::from_str(req_body.as_str()) {
Err(why) => HttpResponse::BadRequest().body(
json!({
"err": "Unable to parse input as request json",
})
.to_string(),
),
Ok(t) => HttpResponse::Ok().body(format!("{:?}", t)),
@saidaspen
saidaspen / Aoc2017D21.kt
Last active August 29, 2020 22:05
Advent of Code 2017 Day 21
fun main() {
val input = java.io.File(ClassLoader.getSystemResource("201721").file).readText().trim()
println("Part 1: " + Day21().part1(input, 5))
println("Part 2: " + Day21().part1(input, 18))
}
typealias G = Grid<Char>
typealias P<A, B> = Pair<A, B>
class Day21 {
@saidaspen
saidaspen / 2017Day21Tests.kt
Created August 25, 2020 00:40
Advent of Code 2017 Day 21 Unit tests
package aoc207
import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.Assertions.assertTrue
import org.junit.jupiter.api.Test
internal class Day21Test {
@Test
fun p1() {
@saidaspen
saidaspen / 2017Day21.kt
Created August 25, 2020 00:33
Advent of Code 2017 Day21 - Does not work
package aoc207
import java.io.File
fun main() {
val input = File(ClassLoader.getSystemResource("201721").file).readText()
println("Part 1: " + Day21(input).part1(5))
}
class Day21(input: String) {