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
Anonymous - 2007-10-31 23:24:50
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