Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion labs/lab05.md
Original file line number Diff line number Diff line change
Expand Up @@ -127,14 +127,21 @@ Now we can apply the above function to all permutations. The function `(check-pa
permutations of nodes and filter those which form a path. If there is a permutation being a path
simultaneously, we have a Hamiltonian path. Otherwise, we return `#f`.
::: details Solution: `find-hamiltonian-path`
```racket
::: code-group
```racket [filter]
(define (find-hamiltonian-path g)
(define perms (permutations (graph-nodes g)))
(let ([paths (filter identity (map (check-path g) perms))])
(if (null? paths)
#f
(car paths))))
```
```racket [ormap]
(define (find-hamiltonian-path g)
(define perms (permutations (graph-nodes g)))
(ormap (check-path g) perms))
```
:::

If you are curious, try to use the function `in-permutations` to compute the `perms` lazily and
compare the perfromance of the two implementations on a larger graph.
Expand Down