RosettaCodeData/Task/Fractran/Haskell/fractran-1.hs
2016-12-05 22:15:40 +01:00

8 lines
280 B
Haskell

import Data.List (find)
import Data.Ratio (Ratio, (%), denominator)
fractran :: (Integral a) => [Ratio a] -> a -> [a]
fractran fracts n = n :
case find (\f -> n `mod` denominator f == 0) fracts of
Nothing -> []
Just f -> fractran fracts $ truncate (fromIntegral n * f)