Your skill will accomplishwhat the force of many cannot PerlMonks

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

 on Sep 11, 2007 at 00:54 UTC ( #638193=note: print w/replies, xml ) Need Help??

Ruby solution
```x = []
"ZBBBCZZ".scan(/((.)\2*)/){ x << [\$~[0]]; x.flatten!}
.flatten is needed else you get
```# => [["Z"], ["BBB"], ["C"], ["ZZ"]]
as result.

But this is quite an ugly solution anyway... in fact, perl looks almost as readable in this example ;)

not sure how to solve this any easier though, hmm i wonder if .each could be used and then another grouping way... I really dont like the regex magic of the ruby solution, cant you guys think of another solution :-)

Replies are listed 'Best First'.
Re^3: Yet Another Rosetta Code Problem (Perl, Ruby, Python, Haskell, ...)
by eyepopslikeamosquito (Chancellor) on Sep 11, 2007 at 22:19 UTC

I really dont like the regex magic of the ruby solution, cant you guys think of another solution :-)
```x = s.split(//).inject([]) {|a,e| (a.last && a.last[e] ? a.last : a) <
+< e; a}

Re^3: Yet Another Rosetta Code Problem (Perl, Ruby, Python, Haskell, ...)
by Anonymous Monk on Sep 11, 2007 at 00:55 UTC
Oh and btw this comment box sucks! [[ newlines should become html br tags! :(
Oh and btw this comment box sucks! [[ newlines should become html br tags! :(
The comment box accepts a limited subset of HTML (with some added Perlmonks-specific markup).
Newlines (and other whitespace) don't behave in HTML as your describe.

If you were logged in, you could update your post to look a little nicer.

-David

Create A New User
Node Status?
node history
Node Type: note [id://638193]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (2)
As of 2019-04-18 22:17 GMT
Sections?
Information?
Find Nodes?
Leftovers?
Voting Booth?
I am most likely to install a new module from CPAN if:

Results (106 votes). Check out past polls.

Notices?