040 Champernowne s constant.sf 676 B

123456789101112131415161718192021222324252627282930
  1. #!/usr/bin/ruby
  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: 59.832s
  12. var str = ''
  13. for i in (1..Inf) {
  14. str += i
  15. str.len >= 1000000 && break
  16. }
  17. var prod = 1
  18. for i in (0..6) {
  19. prod *= str.char(10**i - 1)
  20. }
  21. say prod