Skip to content

Instantly share code, notes, and snippets.

View bartoszm's full-sized avatar

Bartosz Michalik bartoszm

View GitHub Profile
@bartoszm
bartoszm / sample_usage.kt
Created March 17, 2024 21:15
Comparison of two factories using minimal example
package com.amartus.playground.jackson
import com.networknt.schema.InputFormat
import com.networknt.schema.JsonSchemaFactory
import com.networknt.schema.SchemaValidatorsConfig
import com.networknt.schema.SpecVersion
import com.networknt.schema.ValidationMessage
import com.networknt.schema.walk.JsonSchemaWalkListener
import com.networknt.schema.walk.WalkEvent
import com.networknt.schema.walk.WalkFlow
@bartoszm
bartoszm / example.kt
Created March 23, 2023 09:43
Example of controling execution parallerisms with kotlin flows
import kotlinx.coroutines.*
import kotlinx.coroutines.flow.*
import java.util.concurrent.Executors
import kotlin.system.measureTimeMillis
@OptIn(FlowPreview::class)
fun main() = runBlocking {
val urls = (1..1000).map { "https://example.com/todos/$it" }
@bartoszm
bartoszm / Day21p2.kt
Created December 22, 2021 22:23
Day21 part 2
package day21
import java.lang.Long.max
typealias Pos = Int
typealias Step = Int
val scroll3 : Map<Pos, Int> = (1..3).flatMap { f1 ->
(1..3).flatMap { f2 ->
@bartoszm
bartoszm / Day21p1.kt
Created December 22, 2021 22:21
Day21 Part1
package day21
interface Dice {
fun value(): Int
fun values(count: Int): Sequence<Int>
fun rollCount(): Int
}
class DeterministicDice(var value: Int = 1, val max: Int = 100): Dice {
private var rollCount = 0
package day20
import java.nio.file.Files
import java.nio.file.Path
class Enhancer(val code: String) {
private fun getPixel(r: Int, c: Int, data: List<String>) = data.getOrNull(r)?.getOrNull(c) ?: defaultChar
private var defaultChar = '.'
@bartoszm
bartoszm / Day18.kt
Last active December 18, 2021 18:52
Day 18 - ugly solution for both parts
package day18
import java.nio.file.Files
import java.nio.file.Path
sealed class Node(var parent: Regular? = null) {
abstract fun tryExplode(level: Int = 0): Boolean
abstract fun trySplit() : Boolean
internal fun reduce() {
package day14
import java.nio.file.Files
import java.nio.file.Path
class Day14_Part2(val input: Input) {
val rules = input.rules.map { it.first to it.second }.toMap()
private fun find(s: String) = rules[s]
@bartoszm
bartoszm / Day13.kt
Created December 13, 2021 08:06
Day 13 part 1+2 (main solves 2)
abstract class Fold(val line: Int) {
abstract fun transform(p: Pair<Int, Int>): Pair<Int, Int>
}
class FoldX(line: Int) : Fold(line) {
override fun transform(p: Pair<Int, Int>): Pair<Int, Int> {
val x = p.first
val d = line - x
return if(x > line) Pair(x + d*2, p.second) else p
}
package day11
import java.nio.file.Files
import java.nio.file.Path
class State(private val data: Array<IntArray>) {
val inner = data[0].size - 1
val outer = data.size - 1
val flashes by lazy { data.sumOf { row -> row.count { it == 0 } } }
@bartoszm
bartoszm / Day10.kt
Last active December 10, 2021 06:34
Day 10 part 2
package day10
import java.nio.file.Files
import java.nio.file.Path
import kotlin.system.measureTimeMillis
object Day10b {
val mapScore = mapOf(
')' to 1L,