| author | Christian Urban <urbanc@in.tum.de> |
| Fri, 10 Nov 2017 09:00:46 +0000 | |
| changeset 142 | cd6263c3f3fc |
| parent 50 | 9891c9fac37e |
| child 213 | 5a5acaf4b32b |
| permissions | -rw-r--r-- |
| 50 | 1 |
// Part 2 about finding a single tour for a board |
2 |
//================================================ |
|
| 4 | 3 |
|
| 50 | 4 |
// copy any function you need from file knight1.scala |
| 4 | 5 |
|
| 50 | 6 |
type Pos = (Int, Int) // a position on a chessboard |
7 |
type Path = List[Pos] // a path...a list of positions |
|
| 4 | 8 |
|
|
42
a5106bc13db6
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
39
diff
changeset
|
9 |
|
| 50 | 10 |
//(2a) Implement a first-function that finds the first |
11 |
// element, say x, in the list xs where f is not None. |
|
12 |
// In that case return f(x), otherwise none. |
|
|
42
a5106bc13db6
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
39
diff
changeset
|
13 |
|
| 50 | 14 |
def first(xs: List[Pos], f: Pos => Option[Path]): Option[Path] = ... |
|
44
9cfa37c91444
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
43
diff
changeset
|
15 |
|
| 50 | 16 |
//(2b) Implement a function that uses the first-function for |
17 |
// trying out onward moves, and searches recursively for an |
|
18 |
// *open* tour on a dim * dim-board. |
|
|
44
9cfa37c91444
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
43
diff
changeset
|
19 |
|
| 50 | 20 |
def first_tour(dim: Int, path: Path): Option[Path] = ... |
21 |