Skip to content

Commit ad9da38

Browse files
committed
a little nicer puzzle8 with a short demo video
1 parent 37f39bd commit ad9da38

File tree

4 files changed

+39
-8
lines changed

4 files changed

+39
-8
lines changed

notebooks/tps/puzzle8/.teacher/README-puzzle8-corrige-nb.md

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,12 @@ there are no difference - apart from this very cell - between the teacher and th
3737

3838
## problem statement
3939

40+
```{image} media/puzzle8-solving.gif
41+
:align: right
42+
:width: 250px
43+
```
44+
45+
4046
the puzzle is a 3x3 board with 8 tiles numbered from 1 to 8, and a hole (that we
4147
note `0` or `-` depending on the context).
4248
the hole is free to swap with any of the up to 4 adjacent tiles (no diagonal move); here's an example
@@ -383,8 +389,16 @@ one common mistake by first-timers is to
383389

384390
### page.update()
385391

386-
also, as explained in the library documentation, dont' forget to add `page.update()` whenever necessary
387-
without a call to this function, your changes will remain in memory and won't be reflected on the actual screen !
392+
also, as explained in the library documentation, don't forget to add `page.update()` whenever necessary
393+
(you can also call update() on an inner widget if that's more convenient)
394+
but without a call to this function, your changes will remain in memory and won't be reflected on the actual screen !
395+
396+
```{admonition} do not overuse
397+
:class: dropdown
398+
399+
because this function actually involves updating the display, this is a relatively slow operation,
400+
so make sure to not call it too often either !
401+
```
388402

389403
+++
390404

@@ -442,6 +456,7 @@ with our convention that the goal is "1 2 3 4 5 6 7 8 0", here's a sample of
442456
boards with their respective shortest distance; the last one is unreachable
443457

444458
```python
459+
# here are a few solvable problems, with their minimal distance to the goal
445460
problems = []
446461
problems.append(("1 2 3 4 5 6 7 0 8", 1))
447462
problems.append(("1 2 3 4 5 6 0 7 8", 2))
@@ -455,7 +470,7 @@ problems.append(("6 1 8 3 4 5 7 0 2", 21))
455470
problems.append(("6 1 5 7 0 8 4 2 3", 24))
456471
problems.append(("6 1 4 5 3 0 8 2 7", 27))
457472
problems.append(("8 6 7 5 0 1 3 2 4", 30))
458-
# not reachable
473+
# this one is not reachable
459474
problems.append(("6 1 7 4 5 2 3 8 0", float('inf')))
460475
```
461476

@@ -612,5 +627,5 @@ the full documentation is here:
612627
first lines)
613628

614629
using this information, you can identify the bottleneck functions, and then focus on optimizing them
615-
this is how for example how I was able to discard numpy arrays as a possible representation for the boards,
630+
this is how for example how I was able to discard numpy arrays as a possible representation for the boards,
616631
as profiling showed that they were incurring a significant overhead - the way I was using them at least
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../media/

notebooks/tps/puzzle8/README-puzzle8-nb.md

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,12 @@ there are no difference - apart from this very cell - between the teacher and th
3737

3838
## problem statement
3939

40+
```{image} media/puzzle8-solving.gif
41+
:align: right
42+
:width: 250px
43+
```
44+
45+
4046
the puzzle is a 3x3 board with 8 tiles numbered from 1 to 8, and a hole (that we
4147
note `0` or `-` depending on the context).
4248
the hole is free to swap with any of the up to 4 adjacent tiles (no diagonal move); here's an example
@@ -383,8 +389,16 @@ one common mistake by first-timers is to
383389

384390
### page.update()
385391

386-
also, as explained in the library documentation, dont' forget to add `page.update()` whenever necessary
387-
without a call to this function, your changes will remain in memory and won't be reflected on the actual screen !
392+
also, as explained in the library documentation, don't forget to add `page.update()` whenever necessary
393+
(you can also call update() on an inner widget if that's more convenient)
394+
but without a call to this function, your changes will remain in memory and won't be reflected on the actual screen !
395+
396+
```{admonition} do not overuse
397+
:class: dropdown
398+
399+
because this function actually involves updating the display, this is a relatively slow operation,
400+
so make sure to not call it too often either !
401+
```
388402

389403
+++
390404

@@ -442,6 +456,7 @@ with our convention that the goal is "1 2 3 4 5 6 7 8 0", here's a sample of
442456
boards with their respective shortest distance; the last one is unreachable
443457

444458
```python
459+
# here are a few solvable problems, with their minimal distance to the goal
445460
problems = []
446461
problems.append(("1 2 3 4 5 6 7 0 8", 1))
447462
problems.append(("1 2 3 4 5 6 0 7 8", 2))
@@ -455,7 +470,7 @@ problems.append(("6 1 8 3 4 5 7 0 2", 21))
455470
problems.append(("6 1 5 7 0 8 4 2 3", 24))
456471
problems.append(("6 1 4 5 3 0 8 2 7", 27))
457472
problems.append(("8 6 7 5 0 1 3 2 4", 30))
458-
# not reachable
473+
# this one is not reachable
459474
problems.append(("6 1 7 4 5 2 3 8 0", float('inf')))
460475
```
461476

@@ -612,5 +627,5 @@ the full documentation is here:
612627
first lines)
613628

614629
using this information, you can identify the bottleneck functions, and then focus on optimizing them
615-
this is how for example how I was able to discard numpy arrays as a possible representation for the boards,
630+
this is how for example how I was able to discard numpy arrays as a possible representation for the boards,
616631
as profiling showed that they were incurring a significant overhead - the way I was using them at least
401 KB
Loading

0 commit comments

Comments
 (0)