Post Reply 
Dice roll results
05-24-2020, 04:05 PM
Post: #1
Dice roll results
Hello

I am blocked. Any help welcome.

I want to put in a matrix the possible variations of throwing t dice of c sides.
For 3 dice of 3 sides will be something like (3^3 lines):
[[111][112][113][121][122][123][131][132][133][211]….[333]]

My initial aproach is:

EXPORT TossDice(toss,sides)
BEGIN
LOCAL i,j,k,f,c,p,r;
f:=sides^toss;
c:= toss;
MAKEMAT(f,c)▶r;
p:=1;

FOR i FROM 1 TO f DO

FOR j FROM c+1-p DOWNTO 1 DO

FOR k FROM 1 TO c DO

r[i+k-1,j]:=k;

END;

END;

END;

END;

It is a function similar to rolldie() in R software (prob package).

It does not work and it seems to me that I would have to nest a lot of "for" loops to get it. I do not think is the way to get it.
May be in the forum it has appeared before, if so tell me where.

Thanks very much for your help

Toni
Find all posts by this user
Quote this message in a reply
05-24-2020, 06:02 PM
Post: #2
RE: Dice roll results
So you want a deterministic matrix with all the possibilities, not a random distribution, is that it?
Find all posts by this user
Quote this message in a reply
05-24-2020, 09:15 PM (This post was last modified: 05-24-2020 09:17 PM by ijabbott.)
Post: #3
RE: Dice roll results
You should be able to do it with a couple of loops:

EXPORT TossDice(toss,sides)
BEGIN
LOCAL i,j,f,p,r;
f := sides^toss;
MAKEMAT(f,toss)▶r;

FOR i FROM 1 to f DO
p := i-1;
FOR j FROM 1 to toss DO
r[i,j] := 1 + p MOD sides;
p := IP(p / sides);
END;
END;
END;

I haven't tested it.

— Ian Abbott
Find all posts by this user
Quote this message in a reply
05-24-2020, 11:28 PM
Post: #4
RE: Dice roll results
Tongue
Code:
EXPORT TossDice(toss,sides)
BEGIN
  MAKEMAT(IP((I-1)/(sides^(toss-J))) MOD sides+1,sides^toss,toss);
END;

Viga C | TD | FB
Visit this user's website Find all posts by this user
Quote this message in a reply
05-25-2020, 06:28 PM
Post: #5
RE: Dice roll results
Thanks very very much to all.
Beautiful, simple, just much better than what I have finally done with a big mess:

EXPORT RollDi(toss,dice)
BEGIN

LOCAL v,v1,j,k,d,f;
LOCAL t,p,p1,r,r1,l;
d:=dice;
v:=MAKEMAT(J+K,1,d);
v1:=MAKEMAT(0,1,d);
t:=toss;
f:=d^t;
r:=MAKEMAT(0,t,f);
r1:=MAKEMAT(0,1,f);
p:=1;

FOR k FROM 1 TO t DO //loop de t columnas

WHILE p<f DO //rellena cada columna

FOR j FROM 1 TO d DO

MAKEMAT(v[1,j],1,d^(k-1))▶v1;
l:=length(transpose(v1));
CAS.REPLACE(r1,p,v1);
p:=p+l

END;

END;

p:=1;
CAS.REPLACE(r,{t+1-k,1},r1);
r1:=MAKEMAT(0,1,f);

END;

RETURN transpose(r);

END;

It works, at least for low numbers.

Just for future nights with no sleeping, could you tell me how to jump from one point to another while debugging a program? Just to do a complete "loop" for example.


Bye
Find all posts by this user
Quote this message in a reply
05-25-2020, 10:04 PM
Post: #6
RE: Dice roll results
Just insert this in your program code where you need to (re)start debugging :
Code:

DEBUG();
Find all posts by this user
Quote this message in a reply
05-25-2020, 10:08 PM (This post was last modified: 05-25-2020 10:09 PM by pinkman.)
Post: #7
RE: Dice roll results
To be more precise: the DEBUG instruction launches the debugger and halt at the point your program execution is. This acts like a breakpoint.
If you need conditional breakpoint, simply insert this instruction in a conditional statement : IF .. THEN DEBUG();

Thibault
Find all posts by this user
Quote this message in a reply
05-26-2020, 11:05 PM
Post: #8
RE: Dice roll results
Thanks very much.
Easy and very helpful
Find all posts by this user
Quote this message in a reply
05-28-2020, 07:03 AM
Post: #9
RE: Dice roll results
Hello, just to add extra information, if you want to check your results there is this web page:

https://anydice.com/

There, you can play with any number of n-sided dice. Very interesting!, at least for me.

Bye!
Find all posts by this user
Quote this message in a reply
05-30-2020, 03:31 PM
Post: #10
RE: Dice roll results
Hello
Following with the probability I am using a book called:
"Introduction to Pobability and Statistics Using R" by Jay Kerns.

It is full of examples not very complicated. So my intention when I have free time is to practice with the Prime to do the same functions as described in it.

I have already written some with your help. I try to attach the initial program, is my first time so I hope I do it properly.


Thanks

Toni


Attached File(s)
.hpprgm  RollDi.hpprgm (Size: 6.68 KB / Downloads: 3)
Find all posts by this user
Quote this message in a reply
Post Reply 




User(s) browsing this thread: 1 Guest(s)