McNuggets problem: Difference between revisions
→{{header|Haskell}}: Added a sugared variant for comparison
m (→Using Set Comprehension: Cached more of one function) |
(→{{header|Haskell}}: Added a sugared variant for comparison) |
||
Line 331:
in [ v
| 101 > v ]
main :: IO ()
main =
print $
case uncons gaps of
Just (x, _) -> show x
Nothing -> "No unreachable quantities found ..."</lang>
Or equivalently, making use of the list comprehension notation:
<lang haskell>import Data.Set (Set, fromList, member)
import Data.List (uncons)
gaps :: [Int]
gaps = dropWhile (`member` mcNuggets) [100,99 .. 1]
mcNuggets :: Set Int
mcNuggets =
let qc n = [0 .. quot 100 n]
in fromList
[ v
| x <- qc 6
, y <- qc 9
, z <- qc 20
, let v = sum [6 * x, 9 * y, 20 * z]
, 101 > v ]
main :: IO ()
|