Department numbers: Difference between revisions
m
→{{header|Haskell}}
Not a robot (talk | contribs) (Add MAD) |
|||
Line 2,003:
Or, more generally:
<lang Haskell>
options :: Int -> Int -> Int -> [(Int, Int, Int)]
options lo hi total =
( \ds ->
filter even ds
>>= \x ->
filter (/= x) ds
>>= \y ->
[total - (x + y)]
>>= \z ->
)
[lo .. hi]
main :: IO ()
main =
let xs = options 1 7 12
in putStrLn "(Police, Sanitation, Fire)\n"
>> mapM_ print xs
>> mapM_
mapM_ putStrLn ["\nNumber of options: ", show (length xs)]</lang>▼
putStrLn
show (length xs)
]</lang>
Reaching again for a little more syntactic sugar, the options function above could also be re-written either as a list comprehension,
|