Guest User

Untitled

a guest
Oct 18th, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.72 KB | None | 0 0
  1. # $ perl a.pl 1 1 1 1 1 3 4 4 4 4 4
  2. # len: 5 nums: 4 1
  3. # $ perl a.pl 1 1 1 1 1 3 4 4 4 4
  4. # len: 5 nums: 1
  5.  
  6. sub f {
  7. my ($x, @xs) = @_;
  8. if (not @xs) {
  9. (1, $x, 0, ());
  10. } else {
  11. my ($hl, $h, $yl, @ys) = f(@xs);
  12. if ($h eq $x) {
  13. if ($hl + 1 > $yl) {
  14. ($hl + 1, $h, 0, ());
  15. } else {
  16. ($hl + 1, $h, $yl, @ys);
  17. }
  18. } else {
  19. if ($hl == $yl) {
  20. (1, $x, $yl, @ys, $h);
  21. } elsif ($hl > $yl){
  22. (1, $x, $hl, $h);
  23. } else {
  24. (1, $x, $yl, @ys);
  25. }
  26. }
  27. }
  28. }
  29.  
  30. my ($foo, $bar, $len, @nums) = f(undef, @ARGV);
  31. print "len: $len nums: @nums\n";
Add Comment
Please, Sign In to add comment