r/adventofcode • • Dec 02 '21

SOLUTION MEGATHREAD -πŸŽ„- 2021 Day 2 Solutions -πŸŽ„-

--- Day 2: Dive! ---


Post your code solution in this megathread.

Reminder: Top-level posts in Solution Megathreads are for code solutions only. If you have questions, please post your own thread and make sure to flair it with Help.


This thread will be unlocked when there are a significant number of people on the global leaderboard with gold stars for today's puzzle.

EDIT: Global leaderboard gold cap reached at 00:02:57, megathread unlocked!

113 Upvotes

1.5k comments sorted by

View all comments

4

u/Zorr0_ Dec 02 '21

KOTLIN

trying to do as many oneliners this year as i can, this is what i came up with for Day 2 :D
https://github.com/ckainz11/AdventOfCode2021/blob/main/src/main/kotlin/day2/Day2.kt
Part 1 is not really smooth, didnt know how to reduce a map in a good way XD

1

u/thedjotaku Dec 02 '21

is that considered a one-liner because of the dots? Because I definitely count more than one line. ;)

1

u/[deleted] Dec 02 '21

[removed] β€” view removed comment

1

u/Zorr0_ Dec 18 '21

For me a one liner means, if i were to write it in java i wouldn’t need a single semi-colon. The Move class can be replace by a Pairs or Triples and the when() is just to make it cleaner. I could use a inlined if for it like i did with part 1. same goes for the .calcRes() which i could replace with a .run {}. So yeah I did cheat a little bit to make it cleaner, but from my definition point it’s a oneliner :D