Anonymous user
Fraction reduction: Difference between revisions
m
→{{header|Haskell}}
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 -> [
findReduction z@(n1, d1) = go $ commonDigits z
where
Line 1,404 ⟶ 1,405:
decimalWithDrop = realToFrac n2 / realToFrac d2
findReductions :: [Int] -> [
findReductions = (findReduction =<<) . possibleFractions
displayResult ::
displayResult ((n1,d1),(n2,d2),d) = printf "%d/%d = %d/%d by dropping %d\n" n1 d1 n2 d2 d
displayCount :: [
displayCount xs n = do
printf "There are %d %d-digit fractions of which:\n" (length xs) n
|