Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

Re: Yet Another Rosetta Code Problem (Perl, Ruby, Python, Haskell, ...)

by eyepopslikeamosquito (Archbishop)
on Sep 13, 2007 at 02:53 UTC ( [id://638725]=note: print w/replies, xml ) Need Help??


in reply to Yet Another Rosetta Code Problem (Perl, Ruby, Python, Haskell, ...)

For cheap thrills, a Perl 5 version using reduce:

use List::Util qw(reduce); my $s = "ZBBBCZZ"; my $x = reduce { if (@$a && index($a->[-1], $b) >= 0) { $a->[-1] .= $b + } else { push @$a, $b } $a } [], split //, $s;

  • Comment on Re: Yet Another Rosetta Code Problem (Perl, Ruby, Python, Haskell, ...)
  • Download Code

Replies are listed 'Best First'.
Re^2: Yet Another Rosetta Code Problem (Perl, Ruby, Python, Haskell, ...)
by Anonymous Monk on Sep 18, 2007 at 10:18 UTC
    I like the scan/map solution of ruby but I must admit too, that the javascript solution comes out cleanest :) "ZBBBCZZ".match(/((.)\2*)/g)

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://638725]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others meditating upon the Monastery: (5)
As of 2024-04-24 17:27 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found