McNuggets problem: Difference between revisions
Content added Content deleted
m (J draft) |
(→{{header|Haskell}}: Added a Haskell draft) |
||
Line 87: | Line 87: | ||
Maximum non-McNuggets number is 43 |
Maximum non-McNuggets number is 43 |
||
</pre> |
</pre> |
||
=={{header|Haskell}}== |
|||
<lang haskell>import Data.List (nub, sortBy, uncons) |
|||
import Data.Ord (comparing) |
|||
nuggets :: [Int] |
|||
nuggets = |
|||
nub $ |
|||
sortBy (flip (comparing id)) $ |
|||
[0 .. quot 100 6] >>= |
|||
\x -> |
|||
[0 .. quot 100 9] >>= |
|||
\y -> |
|||
[0 .. quot 100 20] >>= |
|||
\z -> |
|||
let v = sum [6 * x, 9 * y, 20 * z] |
|||
in [ v |
|||
| 101 > v ] |
|||
mbMax :: Maybe ((Int, Int), [(Int, Int)]) |
|||
mbMax = uncons $ filter (uncurry (/=)) $ zip [100,99 ..] nuggets |
|||
main :: IO () |
|||
main = |
|||
print $ |
|||
case mbMax of |
|||
Just ((x, _), _) -> show x |
|||
Nothing -> "No unreachable quantities found ..."</lang> |
|||
<pre>43</pre> |
|||
=={{header|J}}== |
=={{header|J}}== |