Project Euler Problem 55

//

I wrote a bunch of these but never posted them up, so I'm just uploading them in bulk now. Not much to say about them at this point.

  1. #!/usr/bin/perl
  2.  
  3. sub p55 {
  4.     my $count = 0;
  5.     for(my $i = 1; $i < 10000; $i++) {
  6.         $count++ if(is_ly($i));
  7.     }
  8.     return $count;
  9. }
  10.  
  11. sub is_ly {
  12.     my $n = shift;
  13.     my @stack;
  14.     push(@stack, $n+reverse($n));
  15.     while(@stack < 50) {
  16.         $n = $stack[@stack-1];
  17.         my $rn = reverse($n);
  18.         return 0 if($n eq $rn);
  19.         push(@stack, $n+$rn);
  20.     }
  21.     return 1;
  22. }
  23.  
  24. my $count = p55();
  25. print "$count\n";