in reply to PPGA - Prolog-Perl Golf Association: Run-length encoding
If you want to golf this:sub runcode { my @ret; while (@_) { my ($x, $c) = (shift, 1); $c++, shift while $_[0] eq $x; push @ret, "$c*$x"; } return @ret; }
I'm sure it can be shrunk, but I'm kinda busy right now.# 78 chars sub RC { #123456789_123456789_123456789_123456789_123456789_123456789_123456789 +_12345678 my@r;while(@_){my($x,$c)=(shift,1);$c++,shift while$_[0]eq$x;push@r," +$c*$x"}@r }
|
|---|