My solutions for Advent of Code 2020 in Kotlin programming language. Advent of Code is an Advent calendar of small programming puzzles by Eric Wastl.
The solutions posted here are my attempts to learn kotlin by solving puzzles. The main implementation goals were:
- Readability: clean, readable, expressive code
- Idiomatic: concise, functional-style kotlin
- Simple: single
Day
class implementing thePuzzle
interface - Minimal: shared code (DRY) between the two parts with minimal external dependencies
- Performance: effective algorithms, preferably solving each puzzle in under a second measured on a
i7-4960HQ@2.6Ghz
machine running macOS- TODO (
Day15,Day23,Day11)
- TODO (
- Day 1: Report Repair π
- Day 2: Password Philosophy π
- Day 3: Toboggan Trajectory π
- Day 4: Passport Processing π
- Day 5: Binary Boarding π
- Day 6: Custom Customs π
- Day 7: Handy Haversacks π
- Day 8: Handheld Halting π€©
- Day 9: Encoding Error π€©
- Day 10: Adapter Array π€©
- Day 11: Seating System π€©
- Day 12: Rain Risk π
- Day 13: Shuttle Search π€©
- Day 14: Docking Data π€©
- Day 15: Rambunctious Recitation π
- Day 16: Ticket Translation π€©
- Day 17: Conway Cubes π€©
- Day 18: Operation Order π€©
- Day 19: Monster Messages π€©
- Day 20: Jurassic Jigsaw π€©
- Day 21: Allergen Assessment π
- Day 22: Crab Combat π
- Day 23: Crab Cups π€©
- Day 24: Lobby Layout π€©
- Day 25: Combo Breaker π
- Based on aoc-kotlin-starter template by Hugh Davey.
- Gradle setup so you can run a specific day or all days on the command line (see Running)
- Timings for each part of each day
- Input for each day automatically exposed in String and List form
- Junit 5 and AssertJ test libraries included (see Testing)
- Starter .gitignore
Project is already setup with gradle. To run the app:
- Navigate to top-level directory on the command line
- Run
./gradlew run
to run all days - Run
./gradlew run --args $DAY
where$DAY
is an integer to run a specific day - Run
./gradlew run --args "$DAY1 $DAY2 $ANOTHERDAY"
to run a subset of days
Project includes JUnit and AssertJ and a stub unit test to get you going. To run all tests:
- Navigate to top-level directory on the command line
- Run
./gradlew test
- Add
--info
,--debug
or--stacktrace
flags for more output
By default, instantiations of Day
classes in tests will use the input files in src/test/resources
, not those
in src/main/resources
. This hopefully gives you flexibility - you could either just copy the real input
into src/test/resources
if you want to test the actual answers, or you could add a file of test data based on the
examples given on the Advent of Code description for the day. The stub Day1Test
class shows a test of the
functionality of Day1
where the test input differs from the actual input.
- Inputs go into
src/main/resources
and follow the naming conventioninput_day_X.txt
- Solutions go into
src/main/kotlin/days
and implement thePuzzle
interface - Solutions follow the naming convention
DayX
- It is assumed all solutions will have two parts
- It is assumed that the puzzle input is provided through the primary constructor
- You can use the
InputReader
methods for reading input To get started simply replacesrc/main/input_day_1.txt
with the real input and the solutions inDay1
with your own