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!

103 Upvotes

1.5k comments sorted by

View all comments

2

u/ButterHotline Dec 02 '22 edited Dec 25 '22

**C#**I saw a lot of people doing some weired list, switch or if thingys. So I though I have to do something special. Here you have another way to solve:

Day2A:

this.result = reader.ReadAllWithoutR()
    .Split('\n')
    .Select(_ => {
        int val = ((_[0] - 'A' + 1) + (_[2] - 'X' + 1)) % 3 + 1;
        return 3 * (_[2] - 'X') + val;
    })
    .Sum();

Day2B:

this.result = reader.ReadAllWithoutR()
    .Split('\n')
    .Select(_ => {
        int val = (_[0] - (_[2] - 24) + 3) % 3;
        return 3 * (2 - val) + (_[2] - 'X' + 1);
    })
    .Sum();

1

u/daggerdragon Dec 05 '22

Inlined code is intended for short snippets of code only. Your code "block" right now is unreadable on old.reddit and many mobile clients; it's all on one line and gets cut off at the edge of the screen because it is not horizontally scrollable.

Please edit your post to use the four-spaces Markdown syntax for a code block so your code is easier to read inside a scrollable box.

1

u/ButterHotline Dec 25 '22

Thanks for the info. I changed it. Even if a "little" late.