Counting Pebbles

Counting Pebbles#

The labyrinth below contains randomly placed pebbles. The mission is to

exit the labyrinth while counting the pebbles.

  1. Initially, ignore the variable nbcailloux and write a program that allows the ant to exit the labyrinth.

  2. The variable nbcailloux will now serve as a counter. Adapt your program so that each time the ant sees a pebble, the variable nbcailloux is incremented by 1.

from laby.global_fr import *
Laby(lignes = 1, colonnes = 10, option = "rocks")
debut()
nbcailloux = 0
### BEGIN SOLUTION
droite()
while (regarde() != Sortie):
    if regarde() == Caillou:
        nbcailloux = nbcailloux + 1
        prend()
        avance()
        droite()
        droite()
        pose()
        droite()
        droite()
    else:
        avance()
### END SOLUTION
ouvre()

The cell below should now display the number of pebbles:

nbcailloux
5
assert est_gagnant()

♣ For a spicier challenge, the mission below is to reach the exit, counting

the webs and pebbles. Proceed in two steps as above.

from laby.global_fr import *
Laby(lignes = 1, colonnes = 10, option = "rocksAndWebs")
debut()
### BEGIN SOLUTION
nbcailloux = 0
nbtoiles = 0
droite()
while (regarde() != Sortie):
    if regarde() == Toile:
        nbtoiles = nbtoiles + 1
        pose()
    if regarde() == Caillou:
        nbcailloux = nbcailloux + 1
        droite()
        droite()
        pose()
        droite()
        droite()
        prend()
        avance()
    else:
        avance()
droite()
droite()
pose()
droite()
droite()
### END SOLUTION
ouvre()

The following cells should display the number of pebbles and webs respectively

### BEGIN SOLUTION
nbcailloux
### END SOLUTION
11
### BEGIN SOLUTION
nbtoiles
### END SOLUTION
6
assert est_gagnant()