Activity 1 Problem Dice program Aim: Based on the Maths 00 activity Problem Dice, Introduce the Program app to simulate 100 rolls of the dice. Creating a program automates a sequence of instructions we used in the previous activity. The following program takes the commands you used in the previous activity to randomly generate 100 rolls on a pair of dice and draw a histogram of the differences. Enter, save and run a program to simulate the differences game. Program app Open program app Create a new program Tap E Enter a name for the program Maximum of 8 characters Tap OK Enter the program Enter the text as shown Some of the text can be entered from menu [Misc Statistics(1) StatGraph] [Misc Statistics(1) Graph ] [I/O Draw ] randlist(100,1,6) a Simulate 100 rolls of a six-sided die and store as a abs(a b) list1 stores the difference between a and b in list1 StatGraph 1,On,,list1,1 Sets StatGraph 1 to On and to draw a using list1 draws the Run the program Tap { to save the program Tap ) to leave the program editor Tap } to run the program Hazeldene publishing 017 Year 9 Mathematics: ClassPad Activities
Do more: Create frequency table Tap P to edit the program Make the adjustments Modify the program to simulate 00 rolls. Record the frequency and draw the histogram. table 00 rolls Difference 0 1 Modify your program to simulate the sum of 00 rolls of a pair of 8-sided dice and record your results. table Difference 0 1 6 7 Hazeldene publishing 017 Year 9 Mathematics: ClassPad Activities
Modify your program to simulate the sum of 00 rolls of a pair of 6-sided dice and record your results. table Sum 0 1 Modify your program to simulate the sum of 00 rolls of three 6-sided dice and record your results. Be patient! table Sum 6 7 8 9 10 11 1 Hazeldene publishing 017 Year 9 Mathematics: ClassPad Activities
Learning notes Detailed instructions: View this video demo of process of creating the program https://www.youtube.com/watch?v=6bceirazei Learning to program: Many people learn coding by modifying work others have done. You will learn more by taking these programs and then modifying than you will starting from scratch. There is a.vcp file on the website that you can download and access the programs using ClassPad Manager on your laptop. The program explained randlist(100,1,6) a randlist(100,1,6) b abs(a-b) list1 StatGraph 1,On,,list1,1 {0,1,,,,} list {0,0,0,0,0,0} list For 1 i To 100 list1[i]+1 d list[d]+1 list[d] DispListEditor Generate lists of 100 random numbers between 1 and 6 and store Calculate the difference between the two dice and store in list1 Set up the Statistics graph: Statgrpah1, set to a using list1 with a frequency of 1 Draw the graph Initialise lists and. List is the differences and list will store how many results have the matching difference This is a loop to go through the 100 rolls. Note the difference between the dice and save as d. Increment the count for that difference. The + 1 is because the differences started at 0 in the first element in the list. Display the Statistics window showing the frequency table Dice Difference Program modified to run with parameters Specify the number of rolls and the number of faces (max 1) on each die each time you run the program. Statistics app only displays 00 elements in a list. This program allows more trials, but on your handheld expect to be waiting a while! Code as shown in screenshot randlist(n,1,faces) a randlist(n,1,faces) b abs(a-b) list {0,1,,,,,6,7,8,9,10,11} list {0,0,0,0,0,0,0,0,0,0,0,0} list For 1 i To n list[i]+1 d list[d]+1 list[d] Hazeldene publishing 017 Year 9 Mathematics: ClassPad Activities
DispListEditor StatGraph 1,On,,list,list Running from main screen Another coding examples Select from a list without replacement The code works by inputting a list and the number of elements you want o select from that list. The code uses parameters and can be called by another program or in the Main screen. E.g. selectn({1,,,,8,1},) will select two elements and they are stored in variable pick. mylist wklist dim(wklist) l 'initialise list to hold selection seq(0,x,1,n,1) pick For 1 i To n 'Select element rand(1,l) p wklist[p] pick[i] 'Delete selected item from list For p+1 j To l wklist[j] wklist[j-1] 'sublist(wklist,1,p-1)+sublist(wklist,p+1,l) wklist Print pick l-1 l Print mylist Print pick Once it is working the Print statements can be deleted. Hazeldene publishing 017 Year 9 Mathematics: ClassPad Activities 6
Example of running program in Main screen Drawing cards Working in Main Draw a card form a regular deck of cards {,,, } suits {1,,,,,6,7,8,9,10,J,Q,K} kind {0,0} s rand(1,) c suits[mod(c,)+1] s[1] kind[mod(c,1)+1] s[] s The symbols for the card suits Writing a program to simulate dealing a random hand of cards {,,, } suits {1,,,,,6,7,8,9,10,J,Q,K} kind seq(x,x,1,,1) pack selectn(pack,) Pause ClrText For 1 i To Locate,1*i,suits[mod(pack[i],)+1] Locate 1,1*i,kind[mod(pack[i],1)+1] Code of first two versions of dice differences program DiceDiff randlist(100,1,6) a randlist(100,1,6) b abs(a-b) list1 StatGraph 1,On,,list1,1 DiceDif randlist(100,1,6) a randlist(100,1,6) b abs(a-b) list1 StatGraph 1,On,,list1,1 {0,1,,,,} list {0,0,0,0,0,0} list For 1 i To 100 list1[i]+1 d list[d]+1 list[d] DispListEditor Hazeldene publishing 017 Year 9 Mathematics: ClassPad Activities 7