Todd Ginsberg
January 27, 2021
66

# Advent of Code in Kotlin: Lessons Learned

An introduction to the Advent of Code and what I learned about solving puzzles in Kotlin.

January 27, 2021

## Transcript

1. Photo by Elena Mozhvilo on Unsplash Photo by Markus Spiske on Unsplash

2. 2020 Unofficial Advent of Code Survey - Jeroen Heijmans

3. Daniel Lin (@ephemient)
Solved every daily puzzle in
four different languages.
ephemient.github.io/aoc2020/

4. Joris Portegies Zwart (@jorispz)
Solves puzzles using Kotlin
Multiplatform.
github.com/jorispz/aoc-2020

5. Jakub Gwóźdź
Solved every puzzle and
provided a visualization.
In Kotlin!
code-2020/

6. Courtesy of @FuriousProgramm
@FuriousProgramm
Also attempting to solve this
puzzle.
Manually.

7. Since 2017, I have solved
each puzzle each day, in
https://todd.ginsberg.com

8. val letters = listOf("A", "B", "C", "D")
val numbers = listOf(1, 2, 3, 4)

9. 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>

10. val letters = listOf("A", "B", "C", "D")

11. val letters = listOf("A", "B", "C", "D")
letters.zipWithNext()
// [(A, B), (B, C), (C, D)]
// List>

12. val letters = listOf("A", "B", "C", "D")

13. val letters = listOf("A", "B", "C", "D")
letters.chunked(2)
// [[A, B], [C, D]]
// List>

14. val letters = listOf("A", "B", "C", "D", "E", "F")

15. 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>

16. val letters = listOf("A", "B", "C", "D", "E", "F")
letters.windowed(3, 3)
// [[A, B, C], [D, E, F]]

17. val letters = listOf("A", "B", "C", "D", "E", "F")
letters.windowed(4, 4, false)
// [[A, B, C, D]]

18. val theString = "Hello"
// Hello!!

19. val theString = "Hello"
// !!Hello

20. val theString = "Left Right"

21. val theString = "Left Right"
theString.substringBefore(" ") // "Left"

22. val theString = "Left Right"
theString.substringBefore(" ") // "Left"
theString.substringAfter(" ") // "Right"

23. val someList = listOf("A", "B", "C")

24. val someList = listOf("A", "B", "C")
someList.any { it.length == 1 } // True!

25. val someList = listOf("A", "B", "C")
someList.all { it.length == 1 } // True!

26. val someList = listOf("A", "B", "C")
someList.none { it.length == 2 } // True!

27. "3".toInt() // 3

28. "3".toInt() // 3
'3'.toInt() // 51

29. fun Char.asInt(): Int =
this.toString().toInt()

30. fun Char.asInt(): Int =
this.toString().toInt()
'3'.asInt() // 3