in reply to 99 Problems in Perl6
Seems that most of the Perl 6 solutions (never mind the hidious lisp concoctions:) are much clumsier than a fairly obvious Perl 5 solution?
Updated: To correctly handle a null list per TimToady's correction below.
sub p09{ @_?reduce{$a->[-1][0]eq$b?push@{$a->[-1]},$b:push@{$a},[$b];$a;}[[shif +t]],@_:() }
which could almost certainly be golfed further, but for the queasy, expands out to a relatively clean:
use List::Util qw[ reduce ]; sub p09 { @_ ? reduce{ $a->[-1][0] eq $b ? push @{ $a->[ -1 ] }, $b : push @{ $a }, [ $b ]; $a; } [[shift]], @_ :() }
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: 99 Problems in Perl6
by TimToady (Parson) on Dec 17, 2006 at 18:34 UTC | |
by BrowserUk (Patriarch) on Dec 17, 2006 at 20:11 UTC |