avan1235 / advent-of-code-2022

Solutions to Advent of Code 2022 in Kotlin

Home Page:https://kotlin-dev.ml/tag/advent-of-code-2022/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

πŸŽ„πŸŽπŸŽ… 2022 Advent of Code in Kotlin πŸŽ…πŸŽπŸŽ„

Project goals

The project goal is to deliver some pretty, readable and concise solutions to Advent of Code 2022 problems all written in Kotlin language. It should show the other developer how some constructions from the language can be used and how to solve some kind of tricky problems that appear during the Advent of Code.

Problems source

You can find all problems at the page of Advent of Code 2022. The description of each problem contains some sample test data, but I also included my input data files from the contest in the resources' directory of the project to make my project working with some sample, real world data.

Solution template

When soling each day problem I use my template of AdventDay that I defined in AdventDay.kt - it's worth looking into this definition by yourself, and also you can read more about it at my blog.

It's enough to create some Kotlin object that inherits from AdventDay to get the solution running. If you're interested in the details, let's look into the definition of the Advent.kt to see how to find all object classes in Kotlin and run some method on them 😎.

To run all solutions, simply call ./gradlew run

Tests

The solutions are tested with the values gathered from adventofcode.com. Every day of Advent has its expected output defined in AdventTest.kt and in order to verify correct state of the outputs for days we run every day solution and catch it standard output stream to compare it with expected value.

To run all tests, simply call ./gradlew test

Problems

The problems solutions are included in project, but for every of them you can also find some corresponding article at my website, where I discuss not only the given problem, but also some cool features of Kotlin or I deep dive into some language constructions.

Problem Solution Tags
Day 1: Calorie Counting Day1.kt sortedDescending, groupSeparatedBy
Day 2: Rock Paper Scissors Day2.kt enum class, infix fun
Day 3: Rucksack Reorganization Day3.kt intersect, windowed, ..
Day 4: Camp Cleanup Day4.kt infix fun
Day 5: Supply Stacks Day5.kt typealias, Stack<T>, operator fun invoke
Day 6: Tuning Trouble Day6.kt windowed, mapIndexedNotNull, asSequence
Day 7: No Space Left On Device Day7.kt groupSeparatedBy, filesystem tree, fold, graph search
Day 8: Treetop Tree House Day8.kt IntProgression, digitToIntOrNull, LazyDefaultMap<K, V>
Day 9: Rope Bridge Day9.kt simulation, named for, downTo, until, operator fun plus, operator fun minus, operator fun unaryMinus
Day 10: Cathode-Ray Tube Day10.kt repeat, private set, sealed interface
Day 11: Monkey in the Middle Day11.kt repeat, private set, sealed interface, modulo operation
Day 12: Hill Climbing Algorithm Day12.kt getOrNull, dijkstra, graph search
Day 13: Distress Signal Day13.kt Comparator<String>, recursion
Day 14: Regolith Reservoir Day14.kt LazyDefaultMap<K, V>, directedTo, operator fun get, operator fun set, simulation

About

Solutions to Advent of Code 2022 in Kotlin

https://kotlin-dev.ml/tag/advent-of-code-2022/


Languages

Language:Kotlin 100.0%