AoC 2022, day 13

Run Settings
LanguageRaku
Language Version
Run Command
use MONKEY-SEE-NO-EVAL; multi compare(UInt:D \a, UInt:D \b) { a <=> b } multi compare(UInt:D \a, @B) { compare([a], @B) } multi compare(@A, UInt:D \b) { compare(@A, [b]) } multi compare(@A, @B --> Order:D) { return +@B == 0 ?? Order::Same !! Order::Less if +@A == 0; return Order::More if +@B == 0; compare(@A[0], @B[0]) or compare(@A.tail(*-1), @B.tail(*-1)) } my @p1 = $*IN.split("\n\n").map({ .lines.map({ EVAL(.subst(/']' <?before ']'>/, '],', :g)) }).Array }); put 'part 1: ', (^+@p1).map(-> \n { n + 1 if compare(|@p1[n]) == Order::Less }).sum; my @p2 = (|@p1[*;*], [[2],], [[6],]).sort({ compare($^a, $^b) }); put 'part 2: ', (@p2.first(* eqv [[2],], :k) + 1) * (@p2.first(* eqv [[6],], :k) + 1);
Editor Settings
Theme
Key bindings
Full width
Lines