読者です 読者をやめる 読者になる 読者になる

mu chance or much chance ?

日々の戯れ言

Project Euler 40

Project Euler

Problem40を解きました.

  • Champernowne's constant

An irrational decimal fraction is created by concatenating the positive integers:

0.123456789101112131415161718192021...

It can be seen that the 12th digit of the fractional part is 1.

If dn represents the nth digit of the fractional part, find the value of the following expression.

d1 × d10 × d100 × d1000 × d10000 × d100000 × d1000000

https://projecteuler.net/problem=40

問題は「チャンパーノウン定数におけるd1 × d10 × d100 × d1000 × d10000 × d100000 × d1000000の値を求めよ,dnは小数第n位の値とする.」.

strNum = '0'
i = 1

while strNum.length <= 1_000_000
  strNum += i.to_s
  i += 1
end

mul = 1
for i in 0..6 do
  mul *= strNum[10**i].to_i
end
p mul

文字列で考えました.