fork download
  1. nextposs (c,r) = filter inboard . map (\(x,y) -> (c+x, r+y)) $
  2. [(-2,-1),(-2,1),(-1,-2),(-1,2),(1,-2),(1,2),(2,-1),(2,1)]
  3. where inboard (c,r) = c>0 && c<9 && r>0 && r<9
  4.  
  5. task a b = map (reverse . map c2f) $ go [[f2c a]] where
  6. go l | null dest = go $ l >>= steps
  7. | otherwise = dest where
  8. dest = filter ((== f2c b) . head) l
  9. steps sc = map (:sc) . nextposs . head $ sc
  10.  
  11. c2f (c,r) = ['@'..] !! c : show r
  12.  
  13. f2c (c:r) = (fromEnum c - fromEnum 'A' + 1, read r :: Int)
  14.  
  15. main = print $ task "B2" "D4"
Success #stdin #stdout 0s 4748KB
stdin
Standard input is empty
stdout
[["B2","A4","C3","B5","D4"],["B2","A4","C3","E2","D4"],["B2","A4","C5","B3","D4"],["B2","A4","C5","E6","D4"],["B2","C4","A3","B5","D4"],["B2","C4","A3","C2","D4"],["B2","C4","A5","B3","D4"],["B2","C4","A5","C6","D4"],["B2","C4","D2","B3","D4"],["B2","C4","D2","F3","D4"],["B2","C4","D6","B5","D4"],["B2","C4","D6","F5","D4"],["B2","C4","E3","C2","D4"],["B2","C4","E3","F5","D4"],["B2","C4","E5","C6","D4"],["B2","C4","E5","F3","D4"],["B2","D1","C3","B5","D4"],["B2","D1","C3","E2","D4"],["B2","D1","E3","C2","D4"],["B2","D1","E3","F5","D4"],["B2","D3","B4","C2","D4"],["B2","D3","B4","C6","D4"],["B2","D3","C1","B3","D4"],["B2","D3","C1","E2","D4"],["B2","D3","C5","B3","D4"],["B2","D3","C5","E6","D4"],["B2","D3","E1","C2","D4"],["B2","D3","E1","F3","D4"],["B2","D3","E5","C6","D4"],["B2","D3","E5","F3","D4"],["B2","D3","F4","E2","D4"],["B2","D3","F4","E6","D4"]]