Daniel Fischer <daniel.is.fisc...@web.de> skrev: > Am Freitag 26 Februar 2010 16:50:42 schrieb Ketil Malde: >>> solutions = [[x1,x2,x3,x4,x5,x6,x7,x8,x9,x10] >>> | x1 <- [0..9]
> First digit can't be 0, so make it [1 .. 9]. > Since you use the fact that the last digit must be the 0, pull all others > from [1 .. 9]. Originally, I pulled from alternating odds (x1 <- [1,3..9] etc) and evens, since this is fairly easy to deduce... I reverted this since the point was to use brute force. >>> solve :: [Int] -> [[Int]] > > Not on a 32-bit system. Word would suffice there, but you don't know that > in advance, so it'd be Int64 or Integer Hm? The Ints are just individual digits here. > I would make the length of the prefix a parameter of solve. I thought about generating a list with solutions for increasing lenghts, so that e.g. 'solve [] !! 10' would solve this particular problem. > solve prefix = > case length prefix of > 10 -> return prefix > l -> do > x <- [0 .. 9] > ... > > over the if-then-else. Yes, much nicer. Thanks for the feedback! -k -- If I haven't seen further, it is by standing in the footprints of giants _______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe