Fraction reduction: Difference between revisions

m
Line 1,370:
 
hasUniqueDigits :: Integral a => a -> Bool
hasUniqueDigits n = dllength ds == length ul
where
ds = digits 10 n
dlul = lengthnub ds
ul = length $ nub ds
 
hasZeros :: Integral a => a -> Bool
Line 1,412 ⟶ 1,411:
displayResult :: (Fraction, Fraction, Int) -> IO ()
displayResult ((n1,d1),(n2,d2),d) = printf "%d/%d = %d/%d by dropping %d\n" n1 d1 n2 d2 d
 
countReductions :: [(Fraction, Fraction, Int)] -> [(Int, Int)]
countReductions = fmap ((,) . length <*> head) . group . sort . fmap (\(_, _, x) -> x)
 
displayCount :: [(Fraction, Fraction, Int)] -> Int -> IO ()
Line 1,420 ⟶ 1,416:
printf "There are %d %d-digit fractions of which:\n" (length xs) n
mapM_ (uncurry (printf "%5d have %d's omitted\n")) (countReductions xs) >> printf "\n"
where
countReductions = fmap ((,) . length <*> head) . group . sort . fmap (\(_, _, x) -> x)
 
main :: IO ()
Anonymous user