Thursday, July 30, 2015

Generating Permutations: TI-84 Plus, Casio Prizm, and HP Prime (updated 10/18/15)

Generating Permutations:  TI-84 Plus, Casio Prizm, and HP Prime

In combinatorics, a permutation is an ordered arrangement of numbers, typically 1 to n.  For n = 3, there are 6 (3!) possible permutations:  {1,2,3}, {1,3,2}, {2,1,3}, {2,3,1}, {3,1,2}, and {3,2,1}.

This blog will focus on generating a random permutation given n elements.

TI-84 Plus:  Using the randIntNoRep function.

For the TI-84 Plus, generating a permutation is rather simple with the randIntNoRep (random integers no reputation function).  The syntax to be used is:

randIntNoRep(1,n,n)

For n = 3, the syntax would be randIntNoRep(1,3,3).  You can find this function by pressing [math], PROB submenu, selecting option 8.


For the Casio Prizm and the HP Prime, a program will be needed.  I gave the program the title SAM for sample (no repeating numbers).  Generally, SAM uses two lists.  The first list is generated by a sequence from 1 to n.  The second is rearranged list.  In order to get sample to not have repeats, during the main loop, as numbers are picked, they are replaced by 0.  During subsequent picks from the first list, the loop tests to see for a nonzero list.  The second list is the output.

Note that with the Casio Prizm that lists must have at least one element to be initialized, where the HP Prime allows for blank lists (lists with zero elements). 

Casio Prizm:  SAM

“N”?→N
Seq(x,x,1,N,1)→List 1
RanInt#(1,N)→C
List 1[C]→M
{M}→List 2
0→List 1[C]
1→I
Do
RanInt#(1,N)→C
List 1[C]→M
If M≠0
Then
Augment(List 2,{M})→List 2
0→List 1[C]
1+I→I
IfEnd
LpWhile I≠N
List 2


HP Prime: SAM

Input:  SAM(n)

EXPORT SAM(n)
BEGIN
LOCAL s,L0,L1,I,c;

L0≔MAKELIST(X,X,1,n,1);
L1≔{ };
I≔0;

REPEAT
c≔RANDINT(1,n);
IF L0(c)≠0 THEN
L1≔CONCAT(L1,{L0(c)});
L0(c)≔0;
I≔I+1;
END;
UNTIL I==n;

RETURN L1;

END;


Update:  Changing c:=RANDINT(n) to c:=RANDINT(1,n) forces the random integer function to choose a number between 1 and 0, since RANDINT(n) allows for zero, allowing for a number to repeat, which is what we don't want.   Eddie

Note:  This is different from the permutation function (nPr, PERM) on your calculator, which calculates the number of arrangements of r from n objects.  (Formula: n!/(n-r)!)
  
Eddie


This blog is property of Edward Shore, 2015.

TI 84 Plus CE: Consolidated Debts

TI 84 Plus CE: Consolidated Debts   Disclaimer: This blog is for informational and academic purposes only. Financial decisions are your ...