
On Tue, Nov 10, 2009 at 8:46 AM, legajid
i wanted to write a program that searches for all combinations of some numbers, the sum of which is a given value. So, i started writing my program, creating a function for each separate phase : creating list of triples, selecting valuable ones, filtering the result.
Looking at my code, i've reduced it several ways; the last version holds on one single line of code.
Please, from the 3 versions i established, which one is " better"? What are the criterias of a "good" code ? What about using many anonymous functions? I think there are other solutions than those i propose.
It could be done using do; import Control.Monad numbers = [9,8..1] f = do x <- numbers y <- numbers z <- numbers guard (y < x && z < y) guard (x+y+z == 19) return [x,y,z]