Created
July 11, 2010 16:37
-
-
Save juster/471662 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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