
18 May
2019
18 May
'19
1:48 a.m.
Hello, On Sat, May 18, 2019 at 12:33:00PM +0800, Magicloud Magiclouds wrote:
I solved the question. But I could not figure out a FP style solution.
Question:
1 - 9, nine numbers. Show all the possible combinations that sum up to 10. Different orders are counted as the same.
A possible solution takes advantage of powersets with the [] Monad. λ> :m +Control.Monad λ> f cs = filterM (\x -> [True, False]) cs λ> filter ((==10) . sum) (f [1..10])