Department numbers: Difference between revisions

m
(Add MAD)
Line 2,003:
 
Or, more generally:
<lang Haskell>options :: Int -> Int -> Int ->----------------- [(Int,DEPARTMENT Int,NUMBERS Int)]------------------
 
options :: Int -> Int -> Int -> [(Int, Int, Int)]
options lo hi total =
( \ds ->
filter even ds >>=
>>= \x ->
filter (/= x) ds >>=
>>= \y ->
[total - (x + y)] >>=
>>= \z ->
case y /= z[ &&(x, lo <=y, z && z <= hi of)
True -> [(x, | y, /= z)] && lo <= z && z <= hi
_ -> [])
)
[lo .. hi]
 
-- TEST ---------------------------------------------- TEST -------------------------
main :: IO ()
main = do
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
mapM_ putStrLn [ "\nNumber of options: ", show (length xs)]</lang>
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,
9,655

edits