Slide 16
Slide 16 text
haskell> queens 4
[[3,1,4,2],[2,4,1,3]]
haskell> queens 5
[[4,2,5,3,1],[3,5,2,4,1],[5,3,1,4,2],[4,1,3,5,2],
[5,2,4,1,3],[1,4,2,5,3],[2,5,3,1,4],[1,3,5,2,4],
[3,1,4,2,5],[2,4,1,3,5]]
haskell> queens 6
[[5,3,1,6,4,2],[4,1,5,2,6,3],
[3,6,2,5,1,4],[2,4,6,1,3,5]]
scala> queens(4)
val res0: List[List[Int]] = List(List(3, 1, 4, 2), List(2, 4, 1, 3))
scala> queens(5)
val res1: List[List[Int]] = List(List(4, 2, 5, 3, 1), List(3, 5, 2, 4, 1), List(5, 3, 1, 4, 2), List(4, 1, 3, 5, 2),
List(5, 2, 4, 1, 3), List(1, 4, 2, 5, 3), List(2, 5, 3, 1, 4), List(1, 3, 5, 2, 4),
List(3, 1, 4, 2, 5), List(2, 4, 1, 3, 5))
scala> queens(6)
val res2: List[List[Int]] = List(List(5, 3, 1, 6, 4, 2), List(4, 1, 5, 2, 6, 3),
List(3, 6, 2, 5, 1, 4), List(2, 4, 6, 1, 3, 5))
Let’s try out both the Scala
program and the Haskell one.
@philip_schwarz