-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path033.hs
22 lines (17 loc) · 1 KB
/
033.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
import Data.List
import Data.Ratio
digits :: Integral x => x -> [x]
digits 0 = []
digits x = x `mod` 10 : digits (x `div` 10)
ratios s f = take 4 [fromInteger x % fromInteger y | x <- [s..f],
y <- [s..f],
let xd = digits x,
let yd = digits y,
let xy = intersect xd yd,
let dividend = (fromInteger x / fromInteger y),
let uniqFloat xs = fromInteger ((xs \\ xy) !! 0),
xy /= [0],
length xy == 1,
(uniqFloat xd) / (uniqFloat yd) == dividend]
digitCancellingProductDenominator s f = denominator . product $ (take 4 (ratios s f))
main = print $ digitCancellingProductDenominator 10 99