78
SOLUTION MEGATHREAD-π- 2022 Day 11 Solutions -π-(self.adventofcode)
submitted 3 years, 1 month ago* (edited 17 minutes after) by daggerdragon to /r/adventofcode (134.8k)
WIKI NEWS
- The FAQ section of the wiki on [Code Formatting](https://www.reddit.com/r/adventofco...
since 3 years, 1 month ago
8 of 8
Tip Reveddit Real-Time can notify you when your content is removed.
your account history
Tip Check if your account has any removed comments.
view my removed comments you are viewing a single comment's thread.
view all comments


Raku (Perl 6)
I'm doing different language each day, all solutions here.
Today's Raku: src
I really wanted to try Raku's Grammar feature for this. Took ages till it worked and anyone even remotely familiar with the language will probably scoff the following, but I tend to like it:
Great minds think alike
Even better: We both did day 4 in C and yesterday in the shell of choice (try Fish, it's great)! I like.
And we both commented about liking
grammar:DI will follow your progress for sure!
Nice! See also my solution, which uses a very similar
grammar.No scoffing here (at all), but a couple of regex tips:
[<num> ', '?]+can be written as<num>+ % ', '. (One or more<num>s separated by', '.)tokens(all butnumandopwhich really are a token) can be better written as arule. These use:sigspacewhich basically makes any whitespace match any whitespace. You can then remove the\ns and be a bit more sloppy with leading/trailing whitespace.Is
%Raku special? I found it in its docs, but nowhere else. Actually looked atrule, but disregarded it thinking whitespace prabably was the reason it didn't work, don't want it to be even more significant. Didn't understand it means any whitespace matches any whitespace, looks cleaner now, thanks!Raku's regexes in general are completely reinvented.
%for βseparated byβ is definitely not a thing in Perl (compatible) regexes; there might be other regex variants that use it, but I haven't seen them.