summaryrefslogtreecommitdiffstats
path: root/033.pl
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2009-05-16 02:22:15 -0500
committerJesse Luehrs <doy@tozt.net>2009-05-16 02:22:15 -0500
commit7dc32fbe3cd63577e8a8b1a19f7e9ef795da45f4 (patch)
tree9719099276b63a44fcd639e10db76129e2976738 /033.pl
parenta847d7fe1f5425b5b2367bf5ca85d4cf049cb7af (diff)
downloadprojecteuler-7dc32fbe3cd63577e8a8b1a19f7e9ef795da45f4.tar.gz
projecteuler-7dc32fbe3cd63577e8a8b1a19f7e9ef795da45f4.zip
problem 33 solution
Diffstat (limited to '033.pl')
-rwxr-xr-x033.pl31
1 files changed, 31 insertions, 0 deletions
diff --git a/033.pl b/033.pl
new file mode 100755
index 0000000..2eed234
--- /dev/null
+++ b/033.pl
@@ -0,0 +1,31 @@
+#!/usr/bin/perl
+use strict;
+use warnings;
+
+my ($num_total, $denom_total) = (1, 1);
+for my $num (10..99) {
+ for my $denom ($num..99) {
+ next if $num == $denom;
+ my $real_frac = $num / $denom;
+
+ my ($n1, $n2) = split //, $num;
+ my $denom_test = $denom;
+ my $frac;
+ if ($denom_test =~ s/$n1//) {
+ next unless $denom_test && $n1;
+ $frac = $n2 / $denom_test;
+ }
+ elsif ($denom_test =~ s/$n2//) {
+ next unless $denom_test && $n2;
+ $frac = $n1 / $denom_test;
+ }
+ else {
+ next;
+ }
+ if ($frac == $real_frac) {
+ $num_total *= $num;
+ $denom_total *= $denom;
+ }
+ }
+}
+print $num_total/$denom_total, "\n";