Jump to content



Photo
- - - - -

Analizy Dice Program


  • Please log in to reply
17 replies to this topic

#1 ex7reme

ex7reme

    Newbie

  • Members
  • Pip
  • 6 posts
  • Gender:Female

  • Calculators:
    CFX-9950GB PLUS

Posted 15 May 2007 - 01:06 PM

Ok so i have an easy dice program, made in fx-9750G plus. I would like to make it loop x times and then tell me how many times it got 1,2,3 etc. but i have no idea were to start? can anyone point me in the right direction, maybe give me some sample code or anything and i'd be very grateful. Shouldn't be too hard right?
:bow:

#2 Menno

Menno

    Casio Freak

  • Members
  • PipPipPipPip
  • 184 posts
  • Gender:Male
  • Location:Netherlands

  • Calculators:
    Casio 880P
    Casio Graph 25+
    Casio fx-9860g sd

Posted 15 May 2007 - 04:39 PM

make 6 variables, say A,B,C,D,E and F

if the dice throws 1 do A=A+1, if the dice throws 2 do B=B+1

at the end of the cyclus print A to F

initialise setting A to F to 0

alternative you could use a list, put the old value plus one in list square one etc

#3 ex7reme

ex7reme

    Newbie

  • Members
  • Pip
  • 6 posts
  • Gender:Female

  • Calculators:
    CFX-9950GB PLUS

Posted 15 May 2007 - 05:59 PM

ok so i get what you're saying, buy i can't get it too work.
I made program called "dice"
[codebox]Int (6*Ran#+1)[/codebox]

Now i want to use another program to call that and collect the stats, i've never called programs before and when i run this i only get zeros:
[codebox]Prog "dice"
If 1
Then A=A+1
Else If 2
Then B=B+1
etc..[/codebox]
I also tried putting Prog "dice" into a variable but i got system error. What am i doing wrong?

#4 Xerxes

Xerxes

    Casio Freak

  • Members
  • PipPipPipPip
  • 130 posts
  • Gender:Male

Posted 15 May 2007 - 06:36 PM

This program is for the FX-9860G but it has to work on the FX-9750G+ too.

{0,0,0,0,0,0}->List 1
For 1->I to 600
Prog "dice"
List 1[Ans]+1->List 1[Ans]
Next
List 1


#5 TyYann

TyYann

    Casio Freak

  • Members
  • PipPipPipPip
  • 107 posts
  • Gender:Male
  • Location:Seoul, South Korea

  • Calculators:
    Casio fx-4000P (since 1988)
    Casio CFX-9850GB PLUS
    Sharp EL-9900
    Casio fx-9860G SD
    Casio fx-9860GII SD
    Casio Graph 90+E
    TI-83 Premium CE (no Python)
    and a 25-column abacus...

Posted 16 May 2007 - 07:53 AM

ok so i get what you're saying, buy i can't get it too work.
I made program called "dice"

Int (6*Ran#+1)

Where is the result stored ?

Better do :
Int (6*Ran#+1)->X
for instance.

Now i want to use another program to call that and collect the stats, i've never called programs before and when i run this i only get zeros:

Prog "dice"
If 1
Then A=A+1
Else If 2
Then B=B+1
etc..
I also tried putting Prog "dice" into a variable but i got system error. What am i doing wrong?

You don't put the prog in a variable, but the result of the prog. Here, I put the variable X in the prog"Dice", the other program becomes :
Prog "dice"
If X=1
Then A=A+1
Else If X=2
Then B=B+1
etc..

This should work.

Personnaly, I don't use a program as long as I don't throw the dice too many times, only a few hundred :rolleyes: .
I use lists :
let's say I want to throw the dice 200 times.
seq(Int (6*Ran#+1),X,1,200,1)->List 1
stores the results of the 200 throws.

Now, let's count them :
List 1=4 makes a list resul full of 0 and 1 where you have 1 if the item in List 1 is equal to 4, 0 otherwise. If you count those 1s, you get the number of 4 in List 1.
To count them, sum them ! Hence :
sum(List 1=4) gives you the number of 4 in List 1
If you want to do that not only for 4, but also from 1 to 6, use a sequence, and store it, say, in List 2
Seq(sum(List 1=X),X,1,6,1)->List 2
And you got your simulation and your results in List 2, you can even directly do your stats on them.

#6 ex7reme

ex7reme

    Newbie

  • Members
  • Pip
  • 6 posts
  • Gender:Female

  • Calculators:
    CFX-9950GB PLUS

Posted 16 May 2007 - 03:18 PM

Better do :

Int (6*Ran#+1)->X
for instance.

You don't put the prog in a variable, but the result of the prog. Here, I put the variable X in the prog"Dice", the other program becomes :
Prog "dice"
   If X=1
   Then A=A+1
   Else If X=2
   Then B=B+1
   etc..


it doesn't work, i just get a bunch of zeros and when i try to write lets say the A variable it's 1. If i code it to only react when the dice shows 1, i can see all the numbers but 1, which is replaced by a zero. I don't think any of the code i wrong, so what is?

#7 ex7reme

ex7reme

    Newbie

  • Members
  • Pip
  • 6 posts
  • Gender:Female

  • Calculators:
    CFX-9950GB PLUS

Posted 17 May 2007 - 09:28 AM

Better do :

Int (6*Ran#+1)->X
for instance.

You don't put the prog in a variable, but the result of the prog. Here, I put the variable X in the prog"Dice", the other program becomes :
Prog "dice"
 If X=1
 Then A=A+1
 Else If X=2
 Then B=B+1
 etc..

This should work.

Personnaly, I don't use a program as long as I don't throw the dice too many times, only a few hundred :rolleyes: .
I use lists :
let's say I want to throw the dice 200 times.
seq(Int (6*Ran#+1),X,1,200,1)->List 1
stores the results of the 200 throws.

Now, let's count them :
List 1=4 makes a list resul full of 0 and 1 where you have 1 if the item in List 1 is equal to 4, 0 otherwise. If you count those 1s, you get the number of 4 in List 1.
To count them, sum them ! Hence :
sum(List 1=4) gives you the number of 4 in List 1
If you want to do that not only for 4, but also from 1 to 6, use a sequence, and store it, say, in List 2
Seq(sum(List 1=X),X,1,6,1)->List 2
And you got your simulation and your results in List 2, you can even directly do your stats on them.


hey hey that bottom stuff works! which is awesome!
but i don't realy understand what's going on could someone please what everything means
here
seq(Int (6*Ran#+1),X,1,200,1)->List 1
and here
Seq(sum(List 1=X),X,1,6,1)->List 2
please?

#8 TyYann

TyYann

    Casio Freak

  • Members
  • PipPipPipPip
  • 107 posts
  • Gender:Male
  • Location:Seoul, South Korea

  • Calculators:
    Casio fx-4000P (since 1988)
    Casio CFX-9850GB PLUS
    Sharp EL-9900
    Casio fx-9860G SD
    Casio fx-9860GII SD
    Casio Graph 90+E
    TI-83 Premium CE (no Python)
    and a 25-column abacus...

Posted 19 May 2007 - 05:18 PM

Seq is an instruction making a sequence of numbers.
Here are the parameters

Seq (formula, Variable, first value for the variable, Last value, step)

In
seq(Int (6*Ran#+1),X,1,200,1)->List 1

the formula is Int (6*Ran#+1), which is your dice.

There is no variable in this formula, but you need one anyways for the syntax of Seq. I used X.

Next, it starts at 1, finishes at 200 with a step of 1, wich means 200 throws.
those 200 throws are stored in List 1

Now comes the tricky part. You need to know how a computer works when it makes a comparison.
If you write 4=4 in your calculator, the result will be 1.
If you write 4=5, the result is 0.

Because, for a computer, 1 means TRUE and 0 means FALSE.

In List 1, we have a sequence of numbers from 1 to 6.
Let's say if it starts like this :
List 1 :
1
3
1
4
1
5
2
4
If I type List 1=1, the calculator will compare each item in List 1 with 1 and answer 1 if this item is equal to 1, 0 otherwise. Those 0 and 1 are stored in ListAns.

List 1 :	 List 1=1 (ListAns)
1		   1
3		   0
1		   1
4		   0
1		   1
5		   0
2		   0
4		   0

Now, we sum the List result (list ans). What is the sum ? Yes, it is 3, which is the number of 1s in List 1 !
So, we can do it again for 2, with sum(List 1=2), then for 3, with sum (List 1=3) etc.

But wait... 1, 2, 3... is also a sequence ! Why not using Seq to do the job for us ?

The formula ?
sum(List 1=X)

The variable ?
X

X starts at ?
1

Finishes at ?
6

with a step of ?
1.

then we get
Seq(sum(List1=X),X,1,6,1)

that we can store in List 2.

#9 ex7reme

ex7reme

    Newbie

  • Members
  • Pip
  • 6 posts
  • Gender:Female

  • Calculators:
    CFX-9950GB PLUS

Posted 19 May 2007 - 09:43 PM

yeah, i get how to use lists to do it now, but that way 255 throws is the max, so tell me why this isn't working, cause i'm going nuts:

[codebox]Int (6*Ran#+1)->X
If X=1
Then A=A+1
Else If X=2
Then B=B+1
etc..[/codebox]

what am i missing? and how do i get it to loop x ammount of times?
LpWhile what? :banghead:

#10 Xerxes

Xerxes

    Casio Freak

  • Members
  • PipPipPipPip
  • 130 posts
  • Gender:Male

Posted 19 May 2007 - 10:26 PM

Before going nuts, have a look at post #4.

#11 TyYann

TyYann

    Casio Freak

  • Members
  • PipPipPipPip
  • 107 posts
  • Gender:Male
  • Location:Seoul, South Korea

  • Calculators:
    Casio fx-4000P (since 1988)
    Casio CFX-9850GB PLUS
    Sharp EL-9900
    Casio fx-9860G SD
    Casio fx-9860GII SD
    Casio Graph 90+E
    TI-83 Premium CE (no Python)
    and a 25-column abacus...

Posted 20 May 2007 - 02:46 PM

Prog "dice"
If X=1
Then A=A+1
Else If X=2
Then B=B+1
etc..

This should work.



it doesn't work, i just get a bunch of zeros and when i try to write lets say the A variable it's 1. If i code it to only react when the dice shows 1, i can see all the numbers but 1, which is replaced by a zero. I don't think any of the code i wrong, so what is?


My mistake. I forgot to correct your syntax.
Then A=A+1
Doesn't store A+1 in A. It ist a logical TEST.

The correct syntax in casio calculator is
A+1->A
The program becomes

Prog "dice"
If X=1
Then A+1->A
Else If X=2
Then B+1->B
etc.

Once again, I'd use lists instead of A~Z, and arrive to the same solution as Xerxes, which has at least 2 advantages :
-The results are stored in a list, which are designed to make stats with.
-If suddenly you want to throw a 20-side dice, a coin (2 sides) or other fancy dices, you don't have to rewrite the full code of both programs. Actually, you can even, with few more lines, make the program ask for the kind of dice and number of throws. This is impossible using A~Z.

By the way, when we write "->" in a program, we mean the [->] key on the calculator.

#12 ex7reme

ex7reme

    Newbie

  • Members
  • Pip
  • 6 posts
  • Gender:Female

  • Calculators:
    CFX-9950GB PLUS

Posted 22 May 2007 - 05:10 AM

the code works!!
Yeah i can do it with lists, but the lists memory let's me only throw the dice 255 times it doesn't get very accurate. And i've also made a prog where you can choose what cind of dice you want and then i comes out in percent how much of each but even with a regular dice those numbers suck, i mean one 13% and one 20%? i want them to be more alike hence more throws then 255. (a 20 case dice is obviously even more inaccurate)

So how do i get the A~Z prog to loop properly? i have to click all the time which is kinda irritating, and i don't get very much help from my manual :greengrin: but thx a bunch on the code!!

#13 TyYann

TyYann

    Casio Freak

  • Members
  • PipPipPipPip
  • 107 posts
  • Gender:Male
  • Location:Seoul, South Korea

  • Calculators:
    Casio fx-4000P (since 1988)
    Casio CFX-9850GB PLUS
    Sharp EL-9900
    Casio fx-9860G SD
    Casio fx-9860GII SD
    Casio Graph 90+E
    TI-83 Premium CE (no Python)
    and a 25-column abacus...

Posted 22 May 2007 - 03:20 PM

Can you post here the A~Z prog, so we can see what's wrong ?

Besides, when I say to use lists like Xerxes, it is just for storage of the sums for each side. I guess you won't try a dice with more than 255 sides...
The 2000 or 2 zillions throws themselves are NOT stored in the lists. I do that a lot those days (I'm curently working on stats and simulation). Trust me (and Xerxes), this is from far the best solution.

For you accuracy problem, you throw the dice how many times ? It is normal you get a huge sample fluctuation for a small sample. I'd like also to see your formula to generate the dice.

Oh. And where do you click on a calc ? You could plug a mouse on it ? :roflol:

#14 Guest_Senso_*

Guest_Senso_*
  • Guests

Posted 22 May 2007 - 03:35 PM

I have already made one
my program was something like this:
Cls
ClearText
0-?A~Z
"Number of trows?"?-?z
For 1-?Y To z
Int(6Ran)+1-?N
N=1=?Isz A
N=2=?Isz B
N=3=?Isz C
N=4=?Isz D
N=5=?Isz E
N=6=?Isz F
Next

This is the base, them you can display the numbers in the graph text ou normal text.
I used a graph mode were i had the relative and absolute percents of the dice numbers.
I hope i have helped.

#15 Xerxes

Xerxes

    Casio Freak

  • Members
  • PipPipPipPip
  • 130 posts
  • Gender:Male

Posted 23 May 2007 - 12:42 PM

@ex7reme:
If you want to learn the accurate way of programming forget the A-Z solution, because it is only justified if your calculator has no indirect addressing.

TyYanns solution have the advantage of no need of programming and an additional list to have a look at the sequence of the random numbers, but you are limited if you want to invastigate a big number of throws.

The general solution of your problem is using an array with indirect addressing. That means, you can use variables with an index like A1, A2, A3 and so on. Unfortunately on the most newer calculators arrays are not implemented anymore, so you have to use lists instead. As TyYann wrotes, with this solution you have the most flexibility for making your analyses.

6->Dim List 1		  ; make a list with 6 elements
For 1->N to 6000	   ; number of throws
Int 6Ran#+1->I		 ; store the throw to I for indexing
List 1[I]+1->List 1[I] ; increment the list element indexed by I
Next				   ; loop
List 1				 ; show the list


#16 Guest_senso_*

Guest_senso_*
  • Guests

Posted 31 May 2007 - 10:53 PM

6->Dim List 1		  ; make a list with 6 elements
For 1->I to 6000	; number of throws
Int 6Ran#+1->I		 ; store the throw to I for indexing
List 1[I]+1->List 1[I] ; increment the list element indexed by I
Next				; loop
List 1				 ; show the list
with this code you will get every time the same results because the loop is defined by I and the ran number is defined eith I too so put the loop or the ran command with other letter.

#17 Xerxes

Xerxes

    Casio Freak

  • Members
  • PipPipPipPip
  • 130 posts
  • Gender:Male

Posted 31 May 2007 - 11:18 PM

Thanks for your attention. I have debugged it.

#18 huhn_m

huhn_m

    Casio Maniac

  • [Legends]
  • PipPipPipPipPipPipPipPip
  • 1957 posts
  • Gender:Male
  • Location:Germany / Dresden
  • Interests:Assembler(!!!)
    Computers and Programming
    Operating Systems
    Programmable Calculators
    Maths and everything arround it

  • Calculators:
    FX-82SX / AFX 2.0+ (ROM 1.03) / FX 1.0+ (ROM 1.03)

Posted 01 June 2007 - 05:24 AM

also some other tipps given here are not too accurate.

You should avoid using the variables X and Y in your programs since the calculator uses them internally for some calculations (graphical ones mostly).
While this does not affect the programs above it should be avoided from the start. (could get handy when debugging larger programs)




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users