Create a Birthday Match Simulation
with
lynxcoding.club
DESCRIPTION
There are usually 365 days in a year. How many students must you have in a classroom in order to be almost certain that two students have the same birthday? 365? Half of 365? Less?
This project lets you find out by experimenting with statistics.
2
Description
Coding a Simulation
Students (grades 5-8) will create a computer simulation to test the probability of an event, in this case of two people in a class having the same birthday.
This activity can be modified to demonstrate the probability of other events, such as the chance of rolling the same number on a die or on multiple dice.
Students will code this app using Lynx at lynxcoding.club.
Students will code the computer to:
Prerequisite Skills - Students should know how to:
Define super- and subprocedures
Add buttons, text boxes, sliders, and turtles
Use basic turtle graphics commands
Success Criteria
Co-construct success criteria with your students but the mathematics of the simulation should work correctly.
3
LEARNING GOALS
Students will learn, and use, these...
4
BIG IDEAS IN CODING | |||
| MAIN IDEAS | | |
CODE &�CONCEPTS | colourunder Event handling and colour detection | if Create conditional statements | settextboxname, setslidername Change values with commands |
random Use a random number generator. | textboxname, slidername Use text box and slider names in commands | stop, stopall Stop single procedures or all action under program control |
GETTING STARTED
Get a LYNX Account and Understand the Layout
5
Get a Lynx Account
Details at lynxcoding.club
6
NO Account
You can try Lynx for free without an account, by clicking on Create a Lynx Project on the home page at lynxcoding.club.
FREE TRIAL Account
For full access, register (click Login/Register located at the top, right side of the Lynx web page).
INDIVIDUAL Account
Convert your trial account to a permanent individual account before end of trial period.
SCHOOL ADMINISTRATOR Account
Convert your trial account to a School Administrator account before end of trial period.
Accounts are free for Canadians thanks to a subsidy by the Government of Canada.
We suggest:
• teacher gets a School Administrator Account
• students get permanent Individual Accounts
• teacher creates a ‘club’ and invites all students
Layout
Save
Add Objects
Files
Procedures
Clipart
Commands
Help
Share
Procedure Pane
Name your Project
Turtle
Work Area (Page)
Command Centre
Clipart Pane
My Projects
Settings
Project Tree
Steps for Students
The BIG Picture! (Table of Contents)
8
Save your work!
LOGIN AND GET STARTED
Log in, CREATE a NEW PROJECT,
NAME it and SAVE it.
9
Get Started
10
2. Click on Create a Lynx Project.
3. Name it something personal �e.g., Talia’s Birthday Match
4. Save
Click this icon
The turtle in this project is used to find “date” matches. �
�This process is repeated until either a match is found or there are no more students to check.
Save your work!
ADD A TURTLE AND TEXT BOX
Add Essential Objects
11
Add Essential Objects - a Turtle and a Text Box
To change the text box’s name, right-click on the text box and type Matches in the top of the dialog box. Click Apply.
12
A text box name must be one word!
TEST A RANDOM NUMBER
Explore How to Use Random
13
Pick a Random Number
Pick a random number from 1-365 and see the results!
Adding a 1 means you won’t get a 0 and the turtle moves forward from 1 to 365 pixels. The 1 is added before the random command.
Random picks a number from 0 to one less than its input, so 0 to 9 in this example.
14
Try this several times. You may not always get a different number, but you won’t be able to predict what number you’ll get each time.
Save your work!
CREATE EVENTS WITH COLOUR
Use Colourunder to trigger an action
15
Check the Dates with Colourunder
To see where the turtle moves have the turtle leave a red dot each time it moves and then return to its original position.
The sequence “pd fd 0 pu” leaves a tiny dot on the page, then the turtle returns to the centre of the work area. It is a bit “magical”, but yes, the turtle leaves a dot when it runs fd 0.
Do you get different patterns of dots each time you run the instruction?
16
A Colour Checking Procedure
This procedure checks if the colour under the turtle is colour number 15 (red).
Using stopall once there’s a match stops the all the action.
Remember: You must use a colour number with colourunder.
The next time and all the other times the turtle moves, it first needs to check if there is a colour under it. To do this, use colourunder. Colourunder checks what the colour under the turtle is.
If colourunder = 15, it means that a random birthday is the exact same date as another random birthday, therefore we have a “match”.
17
Save your work!
SET UP
Set Up Your Experiment
18
Set Up the Turtle
Get the turtle into position
Setheading or seth sets the turtle to a specified direction in degrees.
19
Save your work!
Write a Setup Procedure
Put all the instructions from the previous cards together!
20
Use your turtle’s name followed by a comma. This ensures the turtle on this page follows your instructions. This is useful in case you decide to extend your experiment with one or more turtles later.
Save your work!
Clean will clear the graphics without moving the turtle.
ADD A SLIDER
Set the number of students
21
Add a Slider
Set how many students are in a class
22
Save your work!
Using the Slider
Repeat the OneStudentOneDot procedure for each student in the class
Students reports the number on the slider.
Matches followed by a comma tells the matches text box to follow the next text direction: cleartext or ct.
23
Save your work!
ADD USER INFORMATION
Add a button and instructions
24
Add a Button and Text Boxes
Help your users run the simulation.
A button’s label does not have to be one word. It’s just a label in plain English, not a command.
Drag the corner of the button to show the whole label.
Drag the button to where you want it.
Once in place, right-click on the button, select Frozen, and click Apply.
Test the button several times. How many students do you need (slider value) to get frequent matches?
25
1. Click on the + sign and select Button.�A button named “Nothing” appears.
2. Right-click on the button and give it a clear label, such as Start the Experiment.
3. Click on the arrow in the box next to �On click and select oneclass.
Save your work!
Add Instructions
Add one or more information text boxes
26
Share your Project
Send it to friends or publish it!
27
ADVANCED CODING!
Extend Your Simulation!
28
This section teaches you how to code additional features. New procedures show how many matches there are in many classes of the same size.
It requires adding new procedures, similar to previous ones, but with important differences. Just type the procedures exactly as they are, and you will succeed!
The program you write will:
Set Up a New Page
Set up a second page for Experiment “B”
All slider, text box, turtle, and procedure names must be different from the ones you used before. In this experiment “B”, we are adding “B” to everything.
Remember, use your turtle’s name followed by a comma. This ensures the turtle on this page follows your instructions.
29
Save your work!
Write a New OneClassB Procedure
Test Each Individual Class
Although similar to the Oneclass procedure, note the differences. It uses StudentsB and OneStudentOneDotB, because all these are “unique names” for your second experiment.
MatchesB reports the value in the text box matchesB.
SetMatchesB MatchesB + 1 sets the number in the MatchesB text box to one more than its previous value.
30
Save your work!
Add a ManyClasses Procedure
Add a new Procedure and a Button to run it
31
Set your StudentB and ClassesB sliders to different values and test ManyClasses.
Resize your button, move it to a good location. Then right-click on the button and select Frozen. Click Apply.
Save your work!
In this example, we ran the experiment 50 times with classes of 35 students. We had a total of 56 matches, which means that in some classes, we had more than one match.
Calculate the Average
What Are The Chances
The procedure name must be different from the text box name.
How many students must you have in a class to have an average of “close to 1”
match per class?
32
Save your work!
Credits
Principal Writer……….. Susan Einhorn Contributors.…………...Alain Tougas
Elena Yakovleva
Sergei Soprunov
33
Create a Birthday Match Simulation by Code To Learn is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.