这两天在学习 Haskell,倒不是为了多会一门编程语言,主要是想学习函数式编程的思维方式。进展不快,需要一些练习。于是想起了多年以前的8皇后问题。问题的描述可以参见 wikipedia:
参看 Haskell 的部分,有三种方法,极其简洁明了(Perl版的也很简洁,可是好像很难懂,象是使用字符串处理的方式建模解决数学问题,对Perl的大侠有时真是不得不佩服)。个人喜欢第一个:
There are 92 solutions in total
["A4","B2","C7","D3","E6","F8","G5","H1"]
["A5","B2","C4","D7","E3","F8","G6","H1"]
["A3","B5","C2","D8","E6","F4","G7","H1"]
["A3","B6","C4","D2","E8","F5","G7","H1"]
["A5","B7","C1","D3","E8","F6","G4","H2"]
["A4","B6","C8","D3","E1","F7","G5","H2"]
["A3","B6","C8","D1","E4","F7","G5","H2"]
["A5","B3","C8","D4","E7","F1","G6","H2"]
["A5","B7","C4","D1","E3","F8","G6","H2"]
["A4","B1","C5","D8","E6","F3","G7","H2"]
["A3","B6","C4","D1","E8","F5","G7","H2"]
["A4","B7","C5","D3","E1","F6","G8","H2"]
["A6","B4","C2","D8","E5","F7","G1","H3"]
["A6","B4","C7","D1","E8","F2","G5","H3"]