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]], @_ :() }

Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
Lingua non convalesco, consenesco et abolesco. -- Rule 1 has a caveat! -- Who broke the cabal?
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.

Replies are listed 'Best First'.
Re^2: 99 Problems in Perl6
by TimToady (Parson) on Dec 17, 2006 at 18:34 UTC
    Minor quibble: that would appear to generate a different result when you feed it the null list.

      Good catch++. Updated.


      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      Lingua non convalesco, consenesco et abolesco. -- Rule 1 has a caveat! -- Who broke the cabal?
      "Science is about questioning the status quo. Questioning authority".
      In the absence of evidence, opinion is indistinguishable from prejudice.