Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # $ perl a.pl 1 1 1 1 1 3 4 4 4 4 4
- # len: 5 nums: 4 1
- # $ perl a.pl 1 1 1 1 1 3 4 4 4 4
- # len: 5 nums: 1
- sub f {
- my ($x, @xs) = @_;
- if (not @xs) {
- (1, $x, 0, ());
- } else {
- my ($hl, $h, $yl, @ys) = f(@xs);
- if ($h eq $x) {
- if ($hl + 1 > $yl) {
- ($hl + 1, $h, 0, ());
- } else {
- ($hl + 1, $h, $yl, @ys);
- }
- } else {
- if ($hl == $yl) {
- (1, $x, $yl, @ys, $h);
- } elsif ($hl > $yl){
- (1, $x, $hl, $h);
- } else {
- (1, $x, $yl, @ys);
- }
- }
- }
- }
- my ($foo, $bar, $len, @nums) = f(undef, @ARGV);
- print "len: $len nums: @nums\n";
Add Comment
Please, Sign In to add comment