Well, OK.
(Why do I respond to something like this?)
This is your Prolog ported to Perl. Now somebody else can make that shorter ;-) ...
#!/usr/bin/perl -w use strict; my $input = [12, 2, 2, 'w', 3, 3, 's', 's', 's']; my ($head, @tail) = @{$input}; print "@{runcode(\@tail, $head, 1, [])}"; sub runcode { my ($tail, $current_head, $count, $output) = @_; return [@{$output}, "$count*$current_head"] unless @{$tail}; my ($head, @tail) = @{$tail}; if ("$current_head" eq "$head") { return runcode(\@tail, $head, ++$count, $output) } return runcode(\@tail, $head, 1, [@{$output}, "$count*$current_head"]); }
Christian Lemburg
Brainbench MVP for Perl
http://www.brainbench.com
In reply to Re: PPGA - Prolog-Perl Golf Association: Run-length encoding
by clemburg
in thread PPGA - Prolog-Perl Golf Association: Run-length encoding
by princepawn
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |