Skip to content

Instantly share code, notes, and snippets.

View sjbwylbs's full-sized avatar
🎯
Focusing wechat mall

Evan sjbwylbs

🎯
Focusing wechat mall
  • China Guangdong Shenzhen
View GitHub Profile
@notyy
notyy / gist:2595509
Created May 4, 2012 15:26
骑士问题
问题描述,有一个横8纵8的国际象棋棋盘,也就是坐标x,y都在(1..8)的范围内。
在棋盘的任意坐标上放一个马,马的走步规则,跟中国象棋差不多。。。如果不了解的话请谷歌之
现在给定棋盘上任意坐标,问这个马是否有可能精确的在第3步上走到该坐标?
=======================下面的解法译自haskell==================================
def moveKnight: (Int,Int) => List[(Int,Int)] = (c,r) => {
List((c+2,r-1),(c+2,r+1),(c-2,r-1),(c-2,r+1),
(c+1,r-2),(c+1,r+2),(c-1,r-2),(c-1,r+2)) filter (pos => (1 to 8).contains(pos._1) && (1 to 8).contains(pos._2))
}