• Aucun résultat trouvé

Season 01

N/A
N/A
Protected

Academic year: 2022

Partager "Season 01"

Copied!
6
0
0

Texte intégral

(1)

Season 01Episode 32Algobox

0

Algobox

Season 01

Episode 32 Time frame 1 period

Objectives :

Implement an algorithm with algobox ;

use and understand the notion of repetitive loops in algorithm ;

amend an algorithms with loops ;

introduce the concept of a list ;

use the graph tools of algobox.

Materials :

• ICT room.

• Exercise papers

Original Idea and Work : Jean Lepine

Thanks to him !

1 – Exercise 55 mns

(2)

Algobox

Season 01

Episode 32 Document Exercices

One of the conclusions of the exercise 12.1 is that when you throw two fair dice the probability of the sum 7 to occur is 1

6

0

.

167.

The aim of the session is to devise an algorithm to check that theorical value over 1000 throws.

To do so, we need to simulate the throw of a fair die.

The function

random()

returns a random number between 0 and 0

.

99999999, so

random()*6

returns a random number between 0 and 0

.

99999999.

random()*6+1

is then between 1 and 6

.

99999

then use the function

floor()

to have the nearest integer of the previous number.

Then a possible algorithm is as follow :

Your tasks 1. Implement and test that algorithm under Algobox.

2. Amend the algorithm so that the user is asked the number of throws and the sum he want to check.

3. Amend the algorithm so that the programm returns the number of occurence of each possible sum. Using a list is not an option.

4. Use the graph tools of algobox to create the bar graph of your simulation.

(3)

Algobox

Season 01

Episode 32 Document Solutions

Initial code

1 VARIABLES

2 DéRouge EST_DU_TYPE NOMBRE 3 DéNoir EST_DU_TYPE NOMBRE 4 LesDeux EST_DU_TYPE NOMBRE 5 Lancés EST_DU_TYPE NOMBRE 6 Compteur EST_DU_TYPE NOMBRE 7 DEBUT_ALGORITHME

8 Compteur PREND_LA_VALEUR 0

9 AFFICHER "Somme de deux dés de couleurs différentes"

10 POUR Lancés ALLANT_DE 1 A 1000 11 DEBUT_POUR

12 DéRouge PREND_LA_VALEUR floor(random()*6+1) 13 DéNoir PREND_LA_VALEUR floor(random()*6+1) 14 LesDeux PREND_LA_VALEUR DéRouge+DéNoir 15 SI (LesDeux==7) ALORS

16 DEBUT_SI

17 Compteur PREND_LA_VALEUR Compteur+1

18 FIN_SI

19 FIN_POUR

20 AFFICHER "La somme 7 a été trouvée "

21 AFFICHER Compteur

22 AFFICHER " fois sur 1000 lancers"

23 FIN_ALGORITHME

(4)

Season 01Episode 32Algobox

3

Code with sum and how many throws asked

1 VARIABLES

2 DéRouge EST_DU_TYPE NOMBRE 3 DéNoir EST_DU_TYPE NOMBRE 4 LesDeux EST_DU_TYPE NOMBRE 5 Lancés EST_DU_TYPE NOMBRE 6 Compteur EST_DU_TYPE NOMBRE 7 Combien EST_DU_TYPE NOMBRE 8 Somme EST_DU_TYPE NOMBRE 9 DEBUT_ALGORITHME

10 AFFICHER "Somme de deux dés de couleurs différentes"

11 Compteur PREND_LA_VALEUR 0

12 AFFICHER "Combien de lancer voulez-vous effectuer ?"

13 LIRE Combien

14 AFFICHER "Quelle somme voulez-vous comptabiliser ? "

15 LIRE Somme

16 POUR Lancés ALLANT_DE 1 A Combien 17 DEBUT_POUR

18 DéRouge PREND_LA_VALEUR floor(random()*6+1) 19 DéNoir PREND_LA_VALEUR floor(random()*6+1) 20 LesDeux PREND_LA_VALEUR DéRouge+DéNoir 21 SI (LesDeux==Somme) ALORS

22 DEBUT_SI

23 Compteur PREND_LA_VALEUR Compteur+1

24 FIN_SI

25 FIN_POUR

26 AFFICHER "La somme "

27 AFFICHER Somme

28 AFFICHER " a été trouvée "

29 AFFICHER Compteur 30 AFFICHER " fois sur "

31 AFFICHER Combien 32 AFFICHER " lancers."

(5)

Season 01Episode 32Algobox

4

Code with table of results

1 VARIABLES

2 DéRouge EST_DU_TYPE NOMBRE 3 DéNoir EST_DU_TYPE NOMBRE 4 LesDeux EST_DU_TYPE NOMBRE 5 Lancés EST_DU_TYPE NOMBRE 6 Combien EST_DU_TYPE NOMBRE 7 Somme EST_DU_TYPE NOMBRE 8 apparition EST_DU_TYPE LISTE 9 DEBUT_ALGORITHME

10 AFFICHER "Somme de deux dés de couleurs différentes"

11 AFFICHER "Combien de lancer voulez-vous effectuer ?"

12 LIRE Combien

13 POUR Somme ALLANT_DE 2 A 12 14 DEBUT_POUR

15 apparition[Somme] PREND_LA_VALEUR 0 16 FIN_POUR

17 POUR Lancés ALLANT_DE 1 A Combien 18 DEBUT_POUR

19 DéRouge PREND_LA_VALEUR floor(random()*6+1) 20 DéNoir PREND_LA_VALEUR floor(random()*6+1) 21 LesDeux PREND_LA_VALEUR DéRouge+DéNoir

22 apparition[LesDeux] PREND_LA_VALEUR apparition[LesDeux]+1 23 FIN_POUR

24 AFFICHER "Voici les résultats sur "

25 AFFICHER Combien 26 AFFICHER " lancers :"

27 POUR Somme ALLANT_DE 2 A 12 28 DEBUT_POUR

29 AFFICHER "La somme "

30 AFFICHER Somme

31 AFFICHER " a été obtenue "

32 AFFICHER apparition[Somme]

33 AFFICHER " fois"

34 FIN_POUR 35 FIN_ALGORITHME

(6)

Season 01Episode 32Algobox

5

Code with the bar graph

1 VARIABLES

2 DéRouge EST_DU_TYPE NOMBRE 3 DéNoir EST_DU_TYPE NOMBRE 4 LesDeux EST_DU_TYPE NOMBRE 5 Lancés EST_DU_TYPE NOMBRE 6 Combien EST_DU_TYPE NOMBRE 7 Somme EST_DU_TYPE NOMBRE 8 apparition EST_DU_TYPE LISTE 9 temp EST_DU_TYPE NOMBRE 10 DEBUT_ALGORITHME

11 AFFICHER "Somme de deux dés de couleurs différentes"

12 AFFICHER "Combien de lancer voulez-vous effectuer ?"

13 LIRE Combien

14 POUR Somme ALLANT_DE 2 A 12 15 DEBUT_POUR

16 apparition[Somme] PREND_LA_VALEUR 0 17 FIN_POUR

18 POUR Lancés ALLANT_DE 1 A Combien 19 DEBUT_POUR

20 DéRouge PREND_LA_VALEUR floor(random()*6+1) 21 DéNoir PREND_LA_VALEUR floor(random()*6+1) 22 LesDeux PREND_LA_VALEUR DéRouge+DéNoir

23 apparition[LesDeux] PREND_LA_VALEUR apparition[LesDeux]+1 24 FIN_POUR

25 POUR Somme ALLANT_DE 2 A 12 26 DEBUT_POUR

27 AFFICHER "La somme "

28 AFFICHER Somme

29 AFFICHER " a été obtenue "

30 AFFICHER apparition[Somme]

31 AFFICHER " fois"

32 FIN_POUR

33 AFFICHER "Voici le diagramme en barre associé au résultat :"

34 POUR Somme ALLANT_DE 2 A 12 35 DEBUT_POUR

36 temp PREND_LA_VALEUR floor(100*apparition[Somme]/Combien) 37 TRACER_SEGMENT (Somme,0)->(Somme,temp)

38 FIN_POUR 39

Références

Documents relatifs

I It can be chosen such that the components with variance λ α greater than the mean variance (by variable) are kept. In normalized PCA, the mean variance is 1. This is the Kaiser

Using her mind power to zoom in, Maria saw that the object was actually a tennis shoe, and a little more zooming revealed that the shoe was well worn and the laces were tucked under

It is plain that we are not only acquaintcd with the complex " Self-acquainted-with-A," but we also know the proposition "I am acquainted with A." Now here the

For each method, we obtain formulas that provide bounds on the total number of vector additions in F k b required to perform any of the following three computations, given a vector S

Among these, only 74 cases reported concomitant treatment with antipsychotics (aripiprazole, olanzapine, quetiapine, risperidone and/or ziprasidone) which are known to cause

The signals in this Newsletter are based on information derived from reports of suspected adverse drug reactions available in the WHO global database of individual case safety

The key idea is that we collect meta- data about the attributes in the database (e.g., attribute data type), meta-data about the feature generative functions (e.g., id of the

It is not a problem if the contact person is not totally familiar with the topic 6 , but he/she must indicate the stakeholders having the most diverse opinions possible for each