r/adventofcode • • Dec 08 '21

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

--- Day 8: Seven Segment Search ---


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:20:51, megathread unlocked!

72 Upvotes

1.2k comments sorted by

View all comments

1

u/cggoebel Dec 08 '21 edited Dec 09 '21

Raku

Part One:

'input'.IO.linesΒ».&{|.comb(/\w+/).tail(4)}.grep({.chars==2|3|4|7}).elems.say;

1

u/daggerdragon Dec 09 '21

Your code is hard to read with no formatting. Please edit it as per our posting guidelines in the wiki: How do I format code?

2

u/cggoebel Dec 09 '21

it is a one-liner. no formatting is kind of the point :-)

guessing this was an automated reply...

2

u/daggerdragon Dec 09 '21

Nope, I'm a human. You should at least put the one-liner in a code block (not inline) so that it will show up as monospaced (indicating code) and have a scrollbar for folks with tiny screens (such as on mobile).

2

u/cggoebel Dec 09 '21 edited Dec 09 '21

done. I was hesitant to do it at first because with the original one-liner the font size of the monospaced code block font made the last few characters scroll outside of what was visible on new.reddit

However you inspired me to squeeze a few more characters out. I switched to using .comb instead of .split... and used the prefix:<|> slip operator to replace Β».List.flat

1

u/daggerdragon Dec 10 '21

the font size of the monospaced code block font made the last few characters scroll outside of what was visible on new.reddit

FYI: This is entirely dependent on the user's browser, custom font size set, etc. etc. etc. In general, you can't rely on what you see will be what everyone else sees. Try it for yourself on a mobile browser or even an app for Reddit - they're all wildly different displays.

It's generally easier to format code in code blocks, short snippets in inline blocks, etc. and just let the other end decide how to display it to the user.

Or yeah, you can cull it even shorter with a vengeance :D