4 ms·
This is the kind of things that are a real pleasure to model in Haskell. Here is a nice solution: solve funcs = filter (matches funcs) (possibilities funcs
by lovasoa 7y ago
This is the kind of things that are a real pleasure to model in Haskell. Here is a nice solution:
solve funcs = filter (matches funcs) (possibilities funcs)
matches funcs truths = truths == zipWith (($).($truths).flip) funcs [0..]
possibilities [] = [[]]
possibilities (x:xs) = concatMap (\x -> [True:x, False:x]) (possibilities xs)
all_of = ((and.).)
one_of = ((or.).)
none_of = (((not.or).).)
the_above = take
the_below = drop.(+1)
main = mapM_ putStrLn $
zipWith
(\i s -> "Answer number " ++ (show i) ++ " is " ++ (show s))
[1..] $
head $ solve [
all_of the_below,
none_of the_below,
all_of the_above,
one_of the_above,
none_of the_above,
none_of the_above
]
- lovasoa 7y agoRun it online at: https://repl.it/repls/WeeSlightExams https://repl.it/repls/WeeSlightExams