040 Champernowne s constant.pl 755 B

12345678910111213141516171819202122232425262728293031323334353637
  1. #!/usr/bin/perl
  2. # Author: Daniel "Trizen" Șuteu
  3. # License: GPLv3
  4. # Website: https://github.com/trizen
  5. # An irrational decimal fraction is created by concatenating the positive integers:
  6. # 0.123456789101112131415161718192021...
  7. # It can be seen that the 12th digit of the fractional part is 1.
  8. # If dn represents the nth digit of the fractional part, find the value of the following expression.
  9. # d1 × d10 × d100 × d1000 × d10000 × d100000 × d1000000
  10. # https://projecteuler.net/problem=40
  11. # Runtime: 0.031s
  12. use 5.010;
  13. use strict;
  14. use integer;
  15. my $str = '';
  16. for (my $i = 1 ; ; ++$i) {
  17. $str .= $i;
  18. last if (length($str) >= 1000000);
  19. }
  20. my $prod = 1;
  21. foreach my $i (0 .. 6) {
  22. $prod *= substr($str, 10**($i) - 1, 1);
  23. }
  24. say $prod;