Skip to content

Instantly share code, notes, and snippets.

@juster
Created July 11, 2010 16:37
Show Gist options
  • Save juster/471662 to your computer and use it in GitHub Desktop.
Save juster/471662 to your computer and use it in GitHub Desktop.
# Project Euler Problem #4
# Find the largest palindrome in perl6
use v6;
# This probably takes about 10 minutes to complete?
(my @alpha) = (my @beta) = reverse (100..999);
my $max = 0;
for @alpha -> $x {
shift @beta;
say $x; # DEBUGGING
for @beta -> $y {
my $z = $x * $y;
next unless $z eq $z.flip;
$max = $z if $max < $z;
}
}
say $max;
#!/usr/bin/perl
# Here is the original perl5 version... this runs in a about 0.4 seconds
use warnings;
use strict;
my (@alpha, @beta);
my $max = 0;
@alpha = @beta = reverse 100..999;
for my $x ( @alpha ) {
shift @beta;
for my $y ( @beta ) {
my $z = $x * $y;
next unless $z eq reverse $z;
$max = $z if $max < $z;
}
}
return $max;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment