diff options
author | Jesse Luehrs <doy@tozt.net> | 2009-05-15 21:24:24 -0500 |
---|---|---|
committer | Jesse Luehrs <doy@tozt.net> | 2009-05-15 21:24:24 -0500 |
commit | 467261638ef38efcf878f9ecec020ed9cb9a6c02 (patch) | |
tree | 5c409bc2fd69bddf471bbd11be87f51d3c74d53c | |
parent | ecb58863c7dc0185708ea52fc6ca956c0f8fb1f7 (diff) | |
download | projecteuler-467261638ef38efcf878f9ecec020ed9cb9a6c02.tar.gz projecteuler-467261638ef38efcf878f9ecec020ed9cb9a6c02.zip |
"solution" to problem 40 (what in the world...)
-rwxr-xr-x | 040.pl | 24 |
1 files changed, 24 insertions, 0 deletions
@@ -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"; |