thraxil.org:

Reply to: A Simple Programming Puzzle Seen Through Three Different Lenses

Here’s another Haskell implementation. Like you, I didn’t bother to read ahead before I solved it, and I’m not a proficient Haskell programmer, so I did not think of making a clusterBy. Here goes anyway:

import Data.List;

states = [ ... ]

pairs l = [(x,y) | (x:r) <- tails l, y <- r] statePairs = map (\(x,y) -> (sort (x ++ y),(x,y))) $ pairs states
answer = filter (\((x,),(y,)) -> x == y) $ pairs statePairs


formatting is with Textile syntax. Comments are not displayed until they are approved by a moderator. Moderators will not approve unless the comment contributes value to the discussion.

namerequired
emailrequired
url
remember info?