summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2009-05-15 21:24:24 -0500
committerJesse Luehrs <doy@tozt.net>2009-05-15 21:24:24 -0500
commit467261638ef38efcf878f9ecec020ed9cb9a6c02 (patch)
tree5c409bc2fd69bddf471bbd11be87f51d3c74d53c
parentecb58863c7dc0185708ea52fc6ca956c0f8fb1f7 (diff)
downloadprojecteuler-467261638ef38efcf878f9ecec020ed9cb9a6c02.tar.gz
projecteuler-467261638ef38efcf878f9ecec020ed9cb9a6c02.zip
"solution" to problem 40 (what in the world...)
-rwxr-xr-x040.pl24
1 files changed, 24 insertions, 0 deletions
diff --git a/040.pl b/040.pl
new file mode 100755
index 0000000..de59ff0
--- /dev/null
+++ b/040.pl
@@ -0,0 +1,24 @@
+#!/usr/bin/perl
+use strict;
+use warnings;
+use List::MoreUtils qw/firstidx/;
+
+sub n_digit_number_digits {
+ my ($n) = @_;
+ return 9 * 10**($n - 1) * $n;
+}
+
+my $prev = 0;
+my @total_digits = map { $prev += n_digit_number_digits($_) } 1..6;
+@total_digits = (0, @total_digits);
+
+my $prod = 1;
+for my $exp (0..6) {
+ my $n = 10**$exp;
+ my $digits = firstidx { $_ >= $n } @total_digits;
+ $n -= $total_digits[$digits - 1];
+ my $number = int(($n + $digits - 1) / $digits) + 10**($digits - 1) - 1;
+ my $digit = substr $number, ($n + $digits - 1) % $digits, 1;
+ $prod *= $digit;
+}
+print "$prod\n";