Fraction reduction: Difference between revisions

Content added Content deleted
(added Haskell)
Line 1,414: Line 1,414:


countReductions :: [(Fraction, Fraction, Int)] -> [(Int, Int)]
countReductions :: [(Fraction, Fraction, Int)] -> [(Int, Int)]
countReductions = fmap (\ys -> (length ys, head ys)) . group . sort . fmap (\(_, _, x) -> x)
countReductions = fmap ((,) . length <*> head) . group . sort . fmap (\(_, _, x) -> x)


displayCount :: [(Fraction, Fraction, Int)] -> Int -> IO ()
displayCount :: [(Fraction, Fraction, Int)] -> Int -> IO ()
Line 1,484: Line 1,484:
17 have 8's omitted
17 have 8's omitted
390 have 9's omitted</pre>
390 have 9's omitted</pre>

=={{header|J}}==
=={{header|J}}==
The algorithm generates all potential rational fractions of given size in base 10 and successively applies conditions to restrict the candidates. By avoiding boxing and rational numbers this version is much quicker than that which may be found in the page history.
The algorithm generates all potential rational fractions of given size in base 10 and successively applies conditions to restrict the candidates. By avoiding boxing and rational numbers this version is much quicker than that which may be found in the page history.