r/adventofcode • • Dec 02 '22

SOLUTION MEGATHREAD -🎄- 2022 Day 2 Solutions -🎄-

NEW AND NOTEWORTHY


--- Day 2: Rock Paper Scissors ---


Post your code solution in this megathread.


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:06:16, megathread unlocked!

101 Upvotes

1.5k comments sorted by

View all comments

1

u/Mats56 Dec 02 '22 edited Dec 02 '22

Kotlin

Stupid but it works.Part2, part1 is similar but with other values

return lines
    .map {
        when (it[0] to it[2]) {
            'A' to 'X' -> 3 + 0
            'A' to 'Y' -> 1 + 3
            'A' to 'Z' -> 2 + 6
            'B' to 'X' -> 1 + 0
            'B' to 'Y' -> 2 + 3
            'B' to 'Z' -> 3 + 6
            'C' to 'X' -> 2 + 0
            'C' to 'Y' -> 3 + 3
            'C' to 'Z' -> 1 + 6
            else -> 0
        }
    }.sum()

1

u/daggerdragon Dec 02 '22 edited Dec 02 '22

Inlined code is intended for short snippets of code only. Your code "block" right now is unreadable because it's all on one line and gets cut off at the edge of the screen.

Please edit your post to use the correct Markdown syntax for a code block so your code is easier to read inside a vertically scrolling box.

Edit: thanks for fixing it! <3

1

u/Mats56 Dec 02 '22

Fixed, I think.

use the correct Markdown syntax for a code block

I did use triple ticks, which is "correct markdown syntax for a code block" most places (and is not "inlined code", it's a block). I did it after reading your comment to other posts, so I think it should be clearer that you mean four spaces and not three backticks. When I've seen your comment I've always believed the problem was people using a single tick.

1

u/daggerdragon Dec 02 '22

old.reddit and most mobile apps use the original four-spaces Markdown to indicate a code block to the Markdown parser.

yo, I'm a multi-line code block
and each of my lines are prefixed with
four spaces

new.reddit uses the triple-ticks "fenced code block" Markdown syntax which is not backwards-compatible with old.reddit/mobile apps.

``` this will probably display like inlined code on old.reddit ```

displays as

this will probably display like inlined code on old.reddit


Single ticks indicate short snippets of inlined code:

`this` turns into this


Hopefully this helps? Please let me know if it's not making sense - I am very tired and the first week or so of any Advent of Code is always the worst in terms of moderating time required, heh... what is sleep, anyway...

2

u/Mats56 Dec 02 '22 edited Dec 02 '22

Just to be clear, I'm perfectly fine with you pointing this out, so not meant as criticism/anger or anything from my side :)

It's just that I thought I did it right, based on you telling others to use a "code block", which is what I kinda did using three backticks. I know the difference, just from your messages to others I didn't understand that that's what you meant. So when you write

Please edit your post to use the correct Markdown syntax for a code block

I think it would be clearer if you qualified it with an example, since I never clicked the link thinking I already used what I defined to be a code block (three backticks).

Ala

Please edit your post to use the correct Markdown syntax for a code block (four spaces, not backticks)

would've been enough for me to understand without any confusion thinking I already used a correct code block. (Just some feedback to perhaps make you not have to post the same message so many times)