My Advent of Code solutions written in Kotlin

Related tags

App AOC21
Overview

AOC21

My Advent of Code solutions written in Kotlin

Why Kotlin?

I think Kotlin is a really suitable language for Advent of Code, because it handles list interactions perfectly with functions like map and fold. As most of the days in Advent of Code involve some kind of list manipulation / analysis, this is a really important thing to get right.

Furthermore, Kotlin is very extendable. This allows me to write my own framework, which automates a lot of tasks and allows me to extend normal Kotlin types like strings or lists with my own functions, which saves me a lot of time writing boilerplate code.

Framework? What framework?

I've written a small framework to ease writing solutions and executing them automatically. It fetches your own personal input from the AoC API using a session cookie, caches it into a yml file and reuses this file when needed.

This is all reduced to a single class instantiation, allowing me to start writing solutions in only a couple lines of code:

fun main() {
    Solution(2020, 1)
        .part1 {
            // Sum up all numbers
            lines.toInts().sum()
        }
        .part2 {
            // Multiply all numbers
            lines.toInts().product()
        }
}

Upon running this function, the results automatically get output to the console:

Part 1: 348920
Part 2: 428911409

How do I run the solutions?

I've built this repository assuming you have an IDE to run individual main functions. If you don't, you're out of luck.

First, you'll need a session cookie from Advent of Code. To get it, log in to the website. Then, open the inspector and navigate to the Storage section. You should be able to find a cookie called session. Assign the contents of this cookie to the environment variable named COOKIE.

You can also do this using a .env file:

COOKIE=1234abcd

Then, using your favorite IDE (for example IntelliJ IDEA or Eclipse), execute the main function in the solution file you want to execute (for example nl.chrisb.aoc21.y21.Day1.

Thanks for reading!

You might also like...
Advent of Code template project for Kotlin

Advent of Code Kotlin Template Advent of Code โ€“ an annual event in December since 2015. Every year since then, with the first day of December, a progr

Kotlin fun with Advent of Code 2021

aoc-kotlin Welcome to the Advent of Code1 Kotlin project created by dayanruben using the Advent of Code Kotlin Template delivered by JetBrains. In thi

Advent of Code 2021 implementations in Kotlin

advent-of-code-in-kotlin-2021 Welcome to the Advent of Code1 Kotlin project created by acrane13 using the Advent of Code Kotlin Template delivered by

Advent of Code 2021, using Kotlin

Advent of Code 2021, using Kotlin See https://adventofcode.com/2021, https://kotlinlang.org/. See also "the official GitHub template" by JetBrains. Ge

Advent of Code 2020 - Kotlin

* , _/^\_ * /.-.\ * * `/&\` *

Repository for solving Advent of Code in Kotlin.

Advent of Code 2021 Repository for solving Advent of Code in Kotlin. Getting started Running Project is already setup with gradle. To run the app: Nav

Advent of Code 2021 in Kotlin Multiplatform!

Advent of Code 2021 in Kotlin Multiplatform Structure Each day comes with two parts for you to solve. You'll find a ready-to go and test templates to

My 2021 Advent of Code Repo - Kotlin this year!

๐ŸŽ„ 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 e

Advent of Code 2021, in Kotlin

advent-of-code-kotlin-2021 Welcome to the Advent of Code1 Kotlin project created by mbifulco using the Advent of Code Kotlin Template delivered by Jet

Owner
Chris
hi!
Chris
My solutions for Advent of Code 2021 puzzles, mainly using Kotlin.

Advent of Code 2021 Featuring Kotlin What's that ? https://adventofcode.com/2021/about Advent of Code is an Advent calendar of small programming puzzl

Petrole 0 Dec 2, 2021
Advent of Code 2021: Solutions in Kotlin

Advent of Code 2021 Solutions in Kotlin This repo is my personal attempt at solving the Advent of Code 2021 set of problems with the Kotlin programmin

Todd Ginsberg 33 Nov 28, 2022
๐ŸŽ… Marry XMas ๐ŸŽ„ Kotlin solutions for my Advent of Code 2021 ๐Ÿคถ

Advent of Code 2021 ?? val aMessageFromMe = """ _____________,--, | | | | | | |/ .-.\ HANG IN THERE |_|_|_|_|_|_/ / `. SAN

Nicola Corti 4 Dec 15, 2022
๐ŸŽ„ Solutions to Advent of Code 2021 in Kotlin ๐Ÿ’œ

Advent of Code 2021 in Kotlin These are my solutions to Advent of Code 2021 using the Kotlin language. Each day has its own subpackage. Try the proble

James 3 Feb 28, 2022
Solutions to advent of code 2021 in the gen-Z programming language known as kotlin

Advent Of Code 2021 - Kotlin Edition How to run? Get the kotlin SDK using the sdkman tool: https://sdkman.io/sdks#kotlin Run the commands: ./gradlew

Arijan 2 Jan 7, 2022
My solutions for the Advent of Code 2021. See the link for a playlist with recordings of me solving each puzzle.

Advent of Code 2021 My solutions for the Advent of Code 2021 solved with Kotlin. What is the Advent of Code? Advent of Code is an online event created

The Self-Taught Software Engineer 6 Jan 5, 2022
My Advent Of Code 2021 solutions ๐ŸŽ„๐ŸŽ…

AdventOfCode2021 In this repository, i am about to provide solutions for the Advent of Code1 puzzles using Kotlin language. Footnotes Advent of Code โ€“

null 1 Dec 4, 2021
My advent of code 2021 solutions.

Advent of code 2021 These are my kotlin solutions for however long I manage to take part without giving up. How to run Add a Config.kt file locally an

DownloadPizza 1 Dec 14, 2021
My solutions for advent of code challenges 2021.

advent-of-code-2021 Welcome to the Advent of Code1 Kotlin project created by hiteshchalise using the Advent of Code Kotlin Template delivered by JetBr

Hitesh Chalise 0 Dec 25, 2021
Solution to the 2021 Advent of code challenge in Kotlin. aoc-2021-in-kotlin

advent-of-code-2021 Welcome to the Advent of Code1 Kotlin project created by aniobistanley using the Advent of Code Kotlin Template delivered by JetBr

null 0 Dec 24, 2021