Git Product home page Git Product logo

advent-of-code-2021's Introduction

Advent of Code 2021 ๐ŸŽ„

My solutions for the Advent of Code 2021 written in Kotlin.

This repo is based my Kotlin template for AoC

https://github.com/henningBunk/advent-of-code-2021/blob/main/app/src/y2021/day01/Day01.kt

Logbook

Let's begin :-)
First I followed a plan of giving fold a try but was bummed that I only got the acc and not two values to compare with each other. Therefore, I had to handle list indices. Solved it though. Cleaned it up with some extension functions and without using fold, but rather with list transforms.

After looking at other solutions I learned about the .windowed function and implemented an alternative solution with it.

I wanted to solve it only by transforming the input data without creating variables. It was a challenge but it worked quite well. I introduced two classes for the second part to make it more readable.

Wow, that was harder than I expected. I took forever for that .transpose() function and regretted for the first time not using Python.
For part 2 I could hone my rusty recursion skills which I only used at AoC outside of university. I think I should come back to this problem and work on a simpler and cleaner solution.

Nothing special on this day. I tried to write clean and tested code. I am quite happy with the results and even worked test driven for some parts.
The previous days prepared me well for writing the winning conditions which were quite fun to write. I also wrote one for diagonals which I later discovered were unnecessary.

Again pretty straight forward today. I used a list of mutable lists to count the vents. I like how the extension functions make it very easy to read what's happening in the solve functions.

My naive approach for part 1 could heat up the room pretty good for part 2.

Pretty happy with this one since it only took me only a few minutes and both tests were green on the first try, such a rare sight.
I wonder if I there is a sigma operand for the second calculation, I feel like there should be one.
Also, the runtime is pretty slow since it's a brute force approach. But right now I don't feel like optimizing. Found the trick with the triangle numbers. Which reduced the runtime from 5s to 100ms, not using higher order function reduced it further to 30ms.

I struggled with this one. I chose the wrong datatype to store my remaining candidates for each segment. I used an array of strings and for the operations I used char arrays. Here I got hugely confused with Kotlin's Array and CharArray. Afterwards I read the docs and am wiser now :) I refactored my solution now that it is easier to read and more concise but it is still my original logic. I would like to implement it again using sets because I think that's way more appropriate. Also would like to test out a solution of a colleague who didn't decode the pattern but immediately determined the value of the codes.

Great and interesting day!

// edit:
Tried it again using a map and the approach of my colleague not to decode each segment by itself but rather the numbers as a whole. SO. MUCH. EASIER! See: https://github.com/henningBunk/advent-of-code-2021/blob/main/app/src/y2021/day08/Day08WithoutAnalyzingIndividualSegments.kt

Simple solution with a queue.

Solved this one with my colleague using Ping-Pong-TDD-Pair-Programming. Great practice and lots of fun :)

Nothing special today. I like the solution of putting the octopus in a map with the coordinates as a key. Makes finding the neighbours pretty easy and you don't have to check for limits of the map. Since each octopus knows it's neighbours, I don't need to remember their position of the map which is nice too.

TODO

TODO

TODO

TODO

TODO

TODO

TODO

Usage

  • To create all days for the current year, execute ./gradlew create
  • To create a new day for the current year, execute ./gradlew create --day=9
  • To create a new day for a specific year, execute ./gradlew create --year=2019 --day=9
  • To create all days for a year execute ./gradlew create --year=2019

Thanks

This repo was build using inspiration from these repositories which I am thankful for:

advent-of-code-2021's People

Contributors

henningbunk avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.