> ## Documentation Index
> Fetch the complete documentation index at: https://docs.primastem.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Chapter 6. Chance and infinity

> Book 3. Activities 6.1–6.2.

For printing: [PDF of the whole book, A4](https://github.com/primastem/mintlify-docs/raw/main/en/book-3/files/book-3.pdf)

Chapter goal: a class chart “where the robot's walk ended”, and a square spiral that grows until someone stops it.

We do not introduce the word “probability”. We say “experiment”, “more often”, “less often”, “equally often”, and we count.

## Activity 6.1. A random walk and a die

**We draw.** A class chart “where the robot's walk ended”. It hangs on the wall next to the drawings.

### Goals

**The child can.** Runs an experiment, counts the results with tally marks and draws a conclusion from the count.

**New.**

* Experiment: one run tells you nothing, many runs show what happens more often.
* A bar chart from the count.

### Materials

The 6 × 6 map from Book 1 with 15 cm cells on the floor (or the same grid made from masking tape), an ordinary die per group, a tally sheet with columns 0, 1, 2, 3, 4, 5, 6 and “off the map”, a large sheet for the class chart. Take the marker out of the robot: we do not draw on the map.

Tokens:

* Random Movement;
* repeat × 6.

### For printing

* [Tally sheet](https://docs.primastem.com/en/book-3/sheet-count.md).

### Lesson steps

1. Opening, 5 min. Maps and kits. The teacher shows an empty tally sheet: “The robot will make 6 random steps. Where will it end up? Today the class gives the answer”.
2. Body, 3 min. A child plays the robot and stands on a cell of the map. A neighbor rolls the die: 1 is a step forward, 2 is a step back, 3 is a turn to the left and a step, 4 is a turn to the right and a step, 5 and 6 mean roll again. Where is the child after 6 moves?
3. Predict, 7 min. We count the finish in cells from the start along the grid, without diagonals: how many to the side and how many up or down. Guess: which column of the sheet will be the highest?
4. Robot, 20 min. 10 runs per group. After each run, the Measurer counts the cells, the Checker puts a tally mark, and the Programmer puts the robot back on the start. Do not switch the board off between runs: memory plays no part in this program. Own task: 10 more runs from a start in a corner of the map. How many times did the robot go off the map?
5. Show, 7 min. The groups write their tally marks on the whiteboard. The class adds them up and draws the chart on the large sheet. In the notebook: “One run tells you nothing. Many runs show what happens more often”. The chart goes on the wall.

### Program

Start: a cell near the center of the map, the robot faces up.

Shorthand: `? ×6`, the sign `?` means Random Movement.

Board: top row Random Movement × 6.

Each run goes its own way.

[Run in the simulator](https://simulator.primastem.com/#top=crnd.r006\&s=l1047602\&run)

### Answer

There is no ready answer: this is an experiment. Usually you see two things.

* Columns 1, 3 and 5 are empty if Random Movement moves to a neighboring cell each time and does not turn on the spot. Each step leads to a neighboring cell, and on a checkered map this cell has the other color. There are 6 steps, an even number, so the robot ends on a cell of the same color as the start.
* Most often the finish is 2 cells from the start, less often 4. Least often it is on the start itself or 6 cells away: about 1 run in 10 or fewer. This is the calculation for the case when all four moves come up equally often.

### Find the error

A group did not put the robot back on the start and ran it from where it stopped. (The result is one walk of 60 steps, not 10 walks of 6 steps. The tally marks no longer count the right thing.)

### For fast finishers

Roll the die 30 times and put tally marks for the numbers 1–6. Did all numbers come up equally often? (On average, each number comes up 5 times, but exactly 5 each almost never happens. In a small experiment, the counts are not equal, and this is normal.)

## Activity 6.2. The endless spiral

**We draw.** A square spiral on A2. It grows until someone stops it.

### Goals

**The child can.** Uses a stopping rule to stop a program that does not end by itself.

**New.**

* The function calls itself, and the program does not end.
* A person checks the stopping rule: the robot cannot check it.

### Materials

One A2 sheet per group (the second run goes on the back), ruler, the “decision tree” sheet for fast finishers.

Tokens:

* Function (2);
* Forward (2), Right, Pause;
* number 10;
* arithmetic +10.

### For printing

* [Decision tree](https://docs.primastem.com/en/book-3/sheet-decision-tree.md), for fast finishers.

### Lesson steps

1. Opening, 5 min. Sheets and kits. The teacher runs the spiral in the simulator and stops it with the button: “Today we draw this. The program does not end by itself”.
2. Body, 3 min. “Take a step and tell yourself this again.” When do you stop? Who decides?
3. Predict, 7 min. The program is on the whiteboard. Where is the second Function? It is in the bottom row: the function calls itself. Stopping rule: the Checker stands at the far edge of the sheet and says “edge”, and the Operator presses ▶ during the pause. Guess: how many calls will the robot make before it reaches the edge of the sheet?
4. Robot, 20 min. Run 1 goes to the edge of the sheet, and the Checker counts the calls out loud. Run 2 goes on the back, with a different Operator and the rule “exactly 10 calls”. The Measurer measures the last side. Own task: the group makes up its own stopping rule and tries it on a free part of the back.
5. Show, 7 min. Who had more calls before the edge, and why? The teacher draws a decision tree on the whiteboard: a diamond “Is the robot at the edge of the sheet?”, a “yes” arrow to “stop”, a “no” arrow to “one more call”. This is how the rule would look if the robot could check. In the notebook: “A function can call itself. Then you need a stop, and a person decides when”. Sheets on the floor.

### Program

Start: the cross in the center of the sheet, the robot faces right.

Shorthand: `F10 FN [F+10 R W FN]`, `W` is Pause.

Board: top row Forward 10, Function. Bottom row: Forward +10, Right, Pause, Function.

[Run in the simulator](https://simulator.primastem.com/#top=cfor.n010,cfun\&fn=cfor.a010,crig,cwat,cfun\&s=l1047602\&r=450-450-90\&run)

### Answer

This is the snail from 4.1 without a repeat: the function calls itself, and each side is 10 mm longer than the one before. After 10 calls, the last side is 110 mm, and the drawing is 100 × 110 mm. On A2, with the start in the center, the lines reach the edge after about 40 calls. Pause without a number waits 1 s: this is the Operator's time.

### Find the error

Someone took Pause out of the function. (The robot draws without stops. The Operator cannot press exactly on the 10th call, and the spiral comes out bigger. Pause gives a person time to check the rule.)

### For fast finishers

On the sheet, draw a decision tree for your own stopping rule, as on the whiteboard: a question diamond, arrows “yes” and “no”.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.