in reply to Advent of Code, Day 15, golfed!
Quick golf trick: push() has a return value :)
Replace push@a,/./g;$r||=@a with $r||=push@a,/./g and save 3 strokes.
UPDATE: Oops. that what I get for not testing :(
Alternates:
push@a,@r=/./g}{print$s{-1+map{$u{$_}||=$a[$_]+$s{$g-1}for grep$a[$_]*!$s{$_},$g+@r,$g-!!($g%@r),$g-@r*($g>=@r),++$g*!!($g %@r);($g)=sort{$u{$a}-$u{$b}}keys%u;$s{$g}=delete$u{$g}}@a}
and
# problem description says "resembles a square" push@a,/./g}{print$s{-1+map{$u{$_}||=$a[$_]+$s{$g-1}for grep$a[$_]*!$s{$_},$g+$.,$g-!!($g%$.),$g-$.*($g>=$.),++$g*!!($g %$.);($g)=sort{$u{$a}-$u{$b}}keys%u;$s{$g}=delete$u{$g}}@a}
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: Advent of Code, Day 15, golfed!
by Jasper (Chaplain) on Dec 18, 2021 at 10:32 UTC | |
Re^2: Advent of Code, Day 15, golfed!
by Jasper (Chaplain) on Dec 19, 2021 at 04:39 UTC | |
Re^2: Advent of Code, Day 15, golfed!
by Jasper (Chaplain) on Dec 19, 2021 at 03:46 UTC |
In Section
Obfuscated Code