euler/Problem040.hs

22 lines
616 B
Haskell
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

-- 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 d[n] represents the nth digit of the fractional part, find the value of
-- the following expression.
--
-- d[1] × d[10] × d[100] × d[1000] × d[10000] × d[100000] × d[1000000]
import Euler
nthDigit = go 1
where
go m n = if n < m*10^m
then toDigits (n `div` m) !! (n `mod` m)
else go (m + 1) (n + 10^m)
main = print $ product $ map (nthDigit . (10^)) [0..6]