Skip to content

markaalvaro/advent-2021

Repository files navigation

🎄 Advent of Code 2021

This year I'll be solving the advent problems using Kotlin! 🥂

If you're interested in trying out Kotlin for AoC this year or even next, check out this YouTube video from the Kotlin team. They provide helpful tips for Kotlin functions that help with several past AoC problems, instructions for their AoC giveaway, and a GitHub project template to help you get started!

🗓️ Days

  1. ⭐⭐ (12/01/2021) Solution
  2. ⭐⭐ (12/02/2021) Solution
  3. ⭐⭐ (12/03/2021) Solution
  4. ⭐⭐ (12/04/2021) Solution
  5. ⭐⭐ (12/05/2021) Solution
  6. ⭐⭐ (12/06/2021) Solution
  7. ⭐⭐ (12/07/2021) Solution
  8. ⭐⭐ (12/08/2021) Solution
  9. ⭐⭐ (12/09/2021) Solution
  10. ⭐⭐ (12/10/2021) Solution
  11. ⭐⭐ (12/11/2021) Solution
  12. ⭐⭐ (12/12/2021) Solution
  13. ⭐⭐ (12/13/2021) Solution
  14. ⭐⭐ (12/14/2021) Solution
  15. ⭐⭐ (12/15/2021) Solution
  16. -
  17. -

...

❤️ Community Inspired

After I finish my initial stab at a puzzle, I like to look at other #aoc-2021-in-kotlin repos for inspiration. Lots of times I see solutions that make me think: "Wow! That's cool!" This year I'll be keeping track of my Favorite Solutions from the community (with minor changes to meet this project's style).

🤓 Favorite Kotlin Features

1. windowed(2)

A function that can be used on Iterables and Sequences to look at rolling windows of values. For example listOf(1, 2, 3, 4, 5).windowed(2), would give us [[1, 2], [2, 3], [3, 4], [4, 5]]. You can specify custom window sizes (e.g. window size of 3 to get sub-lists of size 3), and you can specify that you're willing to accept partial windows once you get to the end of the iterable or sequence.

2. count { filter expression }

Pass in a filter expression as an argument to count { ... }, saving the extra line needed by a filter { ... } when a COUNT WHERE is needed.

3. Multi-line String for Regexes

Use multi-line Strings for regexes to avoid needing to escape \ s, which improves regex readability. For example, consider the following greedy whitespace regex (in Java "\\s+"):

boardLines.take(5)
    .flatMap { it.split("""\s+""".toRegex()) }
    .map { it.toInt() }

Releases

No releases published

Packages

No packages published

Languages