Fraction reduction: Difference between revisions

m
Line 1,358:
 
type Fraction = (Int, Int)
type Reduction = (Fraction, Fraction, Int)
 
validIntegers :: [Int] -> [Int]
Line 1,391 ⟶ 1,392:
digitsToIntegral = sum . zipWith (*) (iterate (*10) 1)
 
findReduction :: Fraction -> [(Fraction, Fraction, Int)Reduction]
findReduction z@(n1, d1) = go $ commonDigits z
where
Line 1,404 ⟶ 1,405:
decimalWithDrop = realToFrac n2 / realToFrac d2
 
findReductions :: [Int] -> [(Fraction, Fraction, Int)Reduction]
findReductions = (findReduction =<<) . possibleFractions
 
displayResult :: (Fraction, Fraction, Int)Reduction -> IO ()
displayResult ((n1,d1),(n2,d2),d) = printf "%d/%d = %d/%d by dropping %d\n" n1 d1 n2 d2 d
 
displayCount :: [(Fraction, Fraction, Int)Reduction] -> Int -> IO ()
displayCount xs n = do
printf "There are %d %d-digit fractions of which:\n" (length xs) n
Anonymous user