fork download
  1. m"K"=[1,2]
  2. m"Q"=m"B"++m"R"
  3. m"R"=[1,4,9]
  4. m"B"=[2,8,18]
  5. m"N"=[5]
  6. m"P"=[2]
  7. l%x=[z|z<-l,fst z/=x]
  8. f[_]=[[]]
  9. f l=[(i,j):r|(i@(s,t),a)<-l,(j@(u,v),_)<-l%i,r<-f$(j,a):l%i%j,(s-u)^2+(t-v)^2`elem`m a]
  10.  
  11. main = readLn >>= (mapM_ print . f)
Success #stdin #stdout 0.01s 5280KB
stdin
[((1, 2), "B"), ((0, 1), "R"), ((1, 1), "P"), ((3, 0), "N")]
stdout
[((3,0),(1,1)),((0,1),(1,1)),((1,1),(1,2))]