开发者

How to rearrange this function to return the extended list in Haskell

I am doing problem 68 at project euler and came up with the following code in Haskell to return the list of numbers which fit the (given) solution:

lists = [n|n<- permutations [1..6] , ring n ] 
ring [a,b,c,d,e,f] = (length $ nub $ map开发者_JAVA技巧 sum [[d,c,b],[f,b,a],[e,a,c]]) == 1

This only returns a list of lists of 6 numbers each which fit the solution. What I don't know how to do, is make it return the actual solution, the lists that fit the form:

[d,c,b],[f,b,a],[e,a,c]

How can I make lists return a list of this format?

(PS: I will add in the appropriate functions to return what the site actually wants later)


It's simply

lists = [ [[d,c,b],[f,b,a],[e,a,c]] | n@[a,b,c,d,e,f] <- permutations [1..6], ring n ] 

Or in order to generate the strings:

[ foldl (++) "" $ map show [d,c,b,f,b,a,e,a,c] | n@[a,b,c,d,e,f] <- permutations [1..6], ring n ] 
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜