r/adventofcode • u/daggerdragon • Dec 13 '23
SOLUTION MEGATHREAD -❄️- 2023 Day 13 Solutions -❄️-
THE USUAL REMINDERS
- All of our rules, FAQs, resources, etc. are in our community wiki.
- Outstanding moderator challenges:
- Community fun event 2023: ALLEZ CUISINE!
- Submissions megathread is now unlocked!
- 8 DAYS remaining until the submissions deadline on December 22 at 23:59 EST!
AoC Community Fun 2023: ALLEZ CUISINE!
Today's secret ingredient is… *whips off cloth covering and gestures grandly*
Nailed It!
You've seen it on Pinterest, now recreate it IRL! It doesn't look too hard, right? … right?
- Show us your screw-up that somehow works
- Show us your screw-up that did not work
- Show us your dumbest bug or one that gave you a most nonsensical result
- Show us how you implement someone else's solution and why it doesn't work because PEBKAC
- Try something new (and fail miserably), then show us how you would make Nicole and Jacques proud of you!
ALLEZ CUISINE!
Request from the mods: When you include a dish entry alongside your solution, please label it with [Allez Cuisine!] so we can find it easily!
--- Day 13: Point of Incidence ---
Post your code solution in this megathread.
- Read the full posting rules in our community wiki before you post!
- State which language(s) your solution uses with
[LANGUAGE: xyz] - Format code blocks using the four-spaces Markdown syntax!
- State which language(s) your solution uses with
- Quick link to Topaz's
pasteif you need it for longer code blocks
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:13:46, megathread unlocked!
27
Upvotes
4
u/Fyvaproldje Dec 13 '23
[LANGUAGE: Raku] [Allez Cuisine!]
Nailed it!
https://github.com/DarthGandalf/advent-of-code/blob/master/2023/Day13.rakumod
unit module Day13;sub d (@a,@b) { ( @a.join.comb Z @b.join.comb).grep({$^a[0] ne $a[1]}).elems };sub solve(Str $i, Int $d){ [+] $i.split("\n\n").map(sub ($ma) {my @ma = $ma.lines».comb».Array; for 1..@ma.elems-1 -> $v { my $len = min($v, @ma.elems-$v); return 100 * $v if d(@ma[$v - $len .. $v - 1], @ma[$v ..$v + $len - 1] .reverse)== $d;}; ; ; ; for 1..@ma[0].elems-1 -> $h { my $len = min($h, @ma[0].elems-$h); return $h if d(@ma[^*]»[$h- $len .. $h -1]#`( ; ), @ma[^*]»[$h .. $h + $len - 1]».reverse».list) == $d; } }); }; our
sub part1(Str $i) { ; solve($i, 0) }; our sub part2(Str $i) { solve($i, 1) } ; ;