An introduction to the Advent of Code and what I learned about solving puzzles in Kotlin.
View Slide
Photo by Elena Mozhvilo on Unsplash Photo by Markus Spiske on Unsplash
●
●●
●●●
2020 Unofficial Advent of Code Survey - Jeroen Heijmans
Daniel Lin (@ephemient)Solved every daily puzzle infour different languages.ephemient.github.io/aoc2020/
Joris Portegies Zwart (@jorispz)Solves puzzles using KotlinMultiplatform.github.com/jorispz/aoc-2020
Jakub GwóźdźSolved every puzzle andprovided a visualization.In Kotlin!jakubgwozdz.github.io/advent-of-code-2020/
Courtesy of @FuriousProgramm@FuriousProgrammAlso attempting to solve thispuzzle.Manually.
Since 2017, I have solvedeach puzzle each day, inKotlin and blogged about it.https://todd.ginsberg.com
val letters = listOf("A", "B", "C", "D")val numbers = listOf(1, 2, 3, 4)
val letters = listOf("A", "B", "C", "D")val numbers = listOf(1, 2, 3, 4)letters.zip(numbers)// [(A, 1), (B, 2), (C, 3), (D, 4)]// List>
val letters = listOf("A", "B", "C", "D")
val letters = listOf("A", "B", "C", "D")letters.zipWithNext()// [(A, B), (B, C), (C, D)]// List>
val letters = listOf("A", "B", "C", "D")letters.chunked(2)// [[A, B], [C, D]]// List>
val letters = listOf("A", "B", "C", "D", "E", "F")
val letters = listOf("A", "B", "C", "D", "E", "F")letters.windowed(3)// [[A, B, C], [B, C, D], [C, D, E], [D, E, F]]// List>
val letters = listOf("A", "B", "C", "D", "E", "F")letters.windowed(3, 3)// [[A, B, C], [D, E, F]]
val letters = listOf("A", "B", "C", "D", "E", "F")letters.windowed(4, 4, false)// [[A, B, C, D]]
val theString = "Hello"theString.padEnd(7, '!')// Hello!!
val theString = "Hello"theString.padStart(7, '!')// !!Hello
val theString = "Left Right"
val theString = "Left Right"theString.substringBefore(" ") // "Left"
val theString = "Left Right"theString.substringBefore(" ") // "Left"theString.substringAfter(" ") // "Right"
val someList = listOf("A", "B", "C")
val someList = listOf("A", "B", "C")someList.any { it.length == 1 } // True!
val someList = listOf("A", "B", "C")someList.all { it.length == 1 } // True!
val someList = listOf("A", "B", "C")someList.none { it.length == 2 } // True!
"3".toInt() // 3
"3".toInt() // 3'3'.toInt() // 51
fun Char.asInt(): Int =this.toString().toInt()
fun Char.asInt(): Int =this.toString().toInt()'3'.asInt() // 3
●●●●
●●●●●