A sequence of instructions for performing a task that forms a program or a distinct part of one.

and in the more liberal sense, it could be

A small section of code intended to perform a specific function. Typically the most optimized form of the code, and used quite often.

If you look at the current routines, they all have something in common in that they are simply a means to an end. For example, the number to string routine. Very rarely will you just be putting a number into a string as the program. Rather, part of the program may be converting the number to a string. Same thing goes with finding the index of the maximum list element, its rare that you will use a program to do that only, but instead it is almost always used as part of another program.

Most programs have no need for a clock, and the ones which have timed aspects to them calculate a future time, and check if the current time is greater or less than that future time. Another thing to note is that routines should work on any calculator unless there is significant value to a routine which only works on certain ones. This is why the routines should all have AfPart(N/A) instead of remainder(N,A). I don’t see enough value in this for other programs for it to be a routine.

]]>We know the length of the substring wont be an issue, since we are only taking 1 character instead of all 5 (I purposely put 1 instead of 5 so you woul hopefully be able to learn something).

We know the inputs will be 1-13.75. So the iPart will be 1-13, and the iPart-1 will be 0-12; we know the starting positions will range from 1 to 61; and the string should be 66 characters long.

Therefore, the only possibe explanation is that the input isnt right; the only part of input that changes is Ans. So whatever is in ans must be wrong

]]>but I get invalid dim error using this :sub("ACE _ _2 _ _ _ _ 3 _ _ _ _ 4 _ _ _ _ 5 _ _ _ _ 6 _ _ _ _ 7 _ _ _ _8 _ _ _ _ 9 _ _ _ _10 _ _ _ JACK _ QUEENKING _",1+5iPart(Ans-1),1

]]>` ``Disp "Value:",sub("A23456789TJQK",iPart(Ans),1`

Another note is that your list should not start at 0.25. There are 13 values of cards, so if you start with {0.0,0.25,0.5} your last value should be 12.75. If your list starts with {1,1.25,1.5} your last value should be 13.75.

I'm going to show you them again, but part of learning how to write programs is to do the calculations yourself:

]]>:Disp "Value:", sub("ACE _ _2 _ _ _ _ 3 _ _ _ _ 4 _ _ _ _ 5 _ _ _ _ 6 _ _ _ _ 7 _ _ _ _8 _ _ _ _ 9 _ _ _ _10 _ _ _ JACK _ QUEENKING _",1+(Ans-2)*5,5

]]>⸤DECK

(0.25, 0.50, 0.75, 1.0… 13.75)

:randInt(1,52→T

:⸤DECK(T

:Disp "Value:", sub("ACE _ _2 _ _ _ _ 3 _ _ _ _ 4 _ _ _ _ 5 _ _ _ _ 6 _ _ _ _ 7 _ _ _ _8 _ _ _ _ 9 _ _ _ _10 _ _ _ JACK _ QUEENKING _",1+(Ans-2)*5,5

:Disp "Suit:", sub("SPADES _ _ HEARTS _ _ DIAMONDSCLUBS _ _ _",32fPart(Ans)+1,8

//_ = 1 space

I run and get a Domain Error how do I fix that?

and in TI-BASIC here (the TI-BASIC routine is very slow).

I think the routine on this site might work, but you have to enter the starting pattern yourself.

]]>` ``ClrHome {8,16}→dim([A]) {8,16}→dim([B]) Fill(0,[A]) Fill(0,[B]) 1→[A](1,2) 1→[A](2,3) 1→[A](3,1) 1→[A](3,2) 1→[A](3,3) While 1 For(A,1,8) For(B,1,16) randInt(0,1→[A](A,B) "."→Str1 If [A](A,B)=1 "O"→Str1 Output(A,B,Str1) End End For(A,1,8) For(B,1,16) A+1→D If D=9 1→D A-1→E If E=0 8→E B+1→F If F=17 1→F B-1→G If G=0 16→G [A](D,F)+[A](D,B)+[A](D,G)+[A](E,F)+[A](E,B)+[A](E,G)+[A](A,F)+[A](A,G)→[B](A,B) End End For(A,1,8) For(B,1,16) [B](A,B)→N If ([A](A,B)=1 and N=2)=3 Then 1→[A](A,B) Else 0→[A](A,B) End End End End`

]]>
So, when you take the fParts, you get a list that looks like {0,.25,.5,.75,0,…,.5,.75}

Therefore, when you take 4fPart, you get {0,1,2,3,….,2,3} + 1 would be {1,2,3,4,1,2,3,4,1,2,3,4}

Now lets take a look at what that looks like in the sub function:

` ``sub("SPADES HEARTS DIAMONDSCLUBS ",1,8 returns "SPADES_H" sub("SPADES HEARTS DIAMONDSCLUBS ",2,8 returns "PADES_HE" sub("SPADES HEARTS DIAMONDSCLUBS ",3,8 returns "ADES_HEA" sub("SPADES HEARTS DIAMONDSCLUBS ",4,8 returns "DES_HEAR"`

The first thing to do is to make all the elements in your string the same length, this would make your string:

"SPADES_ _HEARTS_ _DIAMONDSCLUBS_ _ _" where _ represents a space

The second thing to do is figure out how to turn {1,2,3,4} into each of the starting positions {1,9,17,25}. This would be 8*Ans+1. However, we know that Ans is actually 4fPart(Ans)+1, so we can substitute back and get 8*4fPart(Ans)+1 which simplifies to 32fPart(Ans)+1

` ``8(fPart(Ans)≠0)*4fPart(Ans)+1 If fPart(Ans)=.00; 32fPart(Ans)+1 = 32(.00)+1 = 1 If fPart(Ans)=.25; 32fPart(Ans)+1 = 32(.25)+1 = 9 If fPart(Ans)=.50; 32fPart(Ans)+1 = 32(.50)+1 = 17 if fPart(Ans)=.75; 32fPart(Ans)+1 = 32(.75)+1 = 25`

Therefore, the final code would be:

` ``randInt(1,52->T ⸤DECK(T Disp "Value:", sub("A23456789TJQK",int(Ans),1 Disp "Suit:", sub("SPADES HEARTS DIAMONDSCLUBS ",32fPart(Ans)+1,8`

An easier way to do this would be to change your list, so instead of having {1,1.25,1.5,1.75,2,2.25,….13.5,13.75} you would have {1.01,1.09,1.17,1.25,2.01,2.09,….13.17,13.25}

That would mean your code could be

` ``randInt(1,52->T ⸤DECK(T Disp "Value:", sub("A23456789TJQK",int(Ans),1 Disp "Suit:", sub("SPADES HEARTS DIAMONDSCLUBS ",fPart(Ans)e2,8`

:⸤DECK(T

:Disp "Value:", sub("A23456789TJQK",int(Ans),1

:Disp "Suit:", sub("SPADES HEARTS DIAMONDSCLUBS ",4fpart(Ans)+1,8

When I run this I get

ADES HE

SPADES

I was thinking that as long as the values are mostly zeros (which they typically should be) it wouldn't take too long. ]]>

` ``SortD(L2 sum(L2≠0->dim(L2`

Instead of doing

` ``While not(A>dim(L₂ 1+sum(not(cumSum(L₂=0→A seq(L₂(A+(A≥Ans)),A,1,dim(L₂)-1→L₂ End`

Why not instead do

` ``SortD(L₂ While A≠0 and B≤dim(L₂ L₂(B)→A B+1→B End B-2→dim(L₂`

With A=1 and B=1 being set before the loop

Based on my testing, it seems to function the same but is substantially more efficient due to it only editing the list once, not using sequence, and ending sooner when there are fewer values (The other code takes longer the more values there are).

I am not entirely sure if this works exactly the same but so far it seems like it would.