Sum to 100: Difference between revisions
→{{header|Haskell}}: ( small tweak to showing '10 commonest sums' )
(→{{header|Haskell}}: ('10 commonest sums' slightly tidied by using an arrow)) |
(→{{header|Haskell}}: ( small tweak to showing '10 commonest sums' )) |
||
Line 35:
=={{header|Haskell}}==
<lang Haskell>
import Control.Monad (replicateM)
import Control.Arrow ((&&&))
import Data.Char (intToDigit)
Line 91 ⟶ 93:
[ "Sums to 100:\n"
, unlines $ asString <$> filter ((== 100) . asSum) universe
, "\n10 commonest sums (sum, followed by number of routes to it):\n"
, show . take 10 $
sortBy
(on (flip compare) snd)
((head &&& length) <$> group allNonNegativeSums)
, "\n\nFirst positive integer not expressible as a sum of this kind:\n"
, maybeReport (find (uncurry (/=)) (zip [0 ..] (nub allNonNegativeSums)))
Line 107 ⟶ 108:
=> Maybe (a, b) -> String
maybeReport (Just (x, _)) = show x
maybeReport _ = "No gaps found"
</lang>
{{Out}}
Line 136 ⟶ 138:
211
[Finished in 1.
=={{header|Perl 6}}==
|