lirtosiast wrote:
Or this?
Code:
sum(1+int(10fPart(.06039591e^(seq(inString("GKBCQFM HVDJZWPXY",sub(Str1,X,1)),X,1,length(Str1

How about this?

Calculate Scrabble Score of Word in 51 bytes (49 using Ans for input)
Inputs: Str1
Output: Score in Ans

Code:
sum(int(10^(sqrt(sinh(fPart(455atan(seq(inString("FJBCQKDGHVWZXMYP",sub(Str1,X,1)),X,1,length(Str1
For -8 bytes
Boolean

Changes A between 1 And 0.

Code:

G= <Keycode>  xor A→A
DragonScholar71 wrote:

Boolean

Changes A between 1 And 0.

Code:

G= <Keycode>  xor not(A→A

Did you literally just post not(A→A? Laughing
Yes i did, im not the best with optimization and to be honest, i only went over this in my head after the optimization. if it makes you happy, here's the parenthesis version.

Code:

(G= <Keycode>  xor A)->A
I guess I should leave this here.

Detect if code is running on a monochrome or color calc
Inputs:
none
Output:
none, if condition is true, then its color


Code:
If det(angle([[~1

This relies on a parser bug which was fixed between 2.55MP and 4.0. (more specifically between 84C-012 and 84C-020)
This is angle mode-agnostic because [3.14159] and [180] are both non-zero.
Here are some fun routines Smile

Detect if OS version is greater than or equal to 5.1.0.0110
Inputs:
none
Output:
none, if condition is true, then its 5.1.0.0110+


Code:
ClrDraw
Text(1,1,"µ
DispGraph
If pxl-Test(8,2
Disp "5.1.0.0110+


Detect if OS version is equal to 5.2.0.0035 and if it is greater than or equal to 5.2.1.0042
Inputs:
none
Output:
Str1 will contain either <5.2.0, 5.2.0.0035 or 5.2.1.0042+


Code:
"<5.2.0→Str1
0→Ymin:1→ΔY
If Ymax=164
Then
"5.2.0.0035→Str1
SEQ(n+1)
0→nMin
1→w(nMin)
"2w(n)+n"→w
If w(1)=2
"5.2.1.0042+→Str1
End
Disp Str1

I've combined these 2 version checkers together because the 5.2.1 checker relies on tokens that were added in 5.2.0, so to avoid potentially crashing, you should check for 5.2.0 before checking for 5.2.1.
Getting the type of Ans

Each of these routines can distinguish between two or more possible types contained in Ans. The type is printed, leaving Ans unchanged; this can be changed to a non-modifying variable write using, say, For( or IS>(. If an unsupported type is passed, expect errors.

This post was originally initiated by my discovery of List vs. String using attached formulas. The rest of the routines are assembled from the community and my own attempts to fill out the table of distinguishable types over the past 24 hours. Notably, since toString( fails on strings (go figure), generic strings cannot be distinguished from the other types.

Number vs. List or String (by bfr)

Code:
DelVar AFor(B,1,1
Ans->A:Ans->B
If A=B:Then
Disp "NUMBER"
Else
Disp "LIST OR STRING"


Number vs. List vs. (Evaluatable) String

If Ans is a string, it must evaluate to a list. If Ans is a list with only one unique value, it cannot be distinguished from a string (and vice-versa).

Code:
DelVar AFor(B,1,1
Ans->A:Ans->B
If A=B:Then
Disp "NUMBER"
Else
If max(|LA)=min(|LA:Then
Disp "LIST OR STRING"
Else
SortA(|LA:SortD(|LB
If max(|LA!=|LB:Then
Disp "LIST"
Else
Disp "STRING"


Number vs. List vs. Matrix (CE or newer)

This routine requires toString(, which is only available on the CE or newer.

Code:
If "["=sub(toString(Ans),1,1:Then
Disp "MATRIX"
Else
If "{"=sub(toString(Ans),1,1:Then
Disp "LIST"
Else
Disp "NUMBER"


List vs. Matrix (Destroys Ans)

Code:
DelVar AFor(B,1,1
dim(Ans->A:Ans->B
If A=B:Then
Disp "LIST"
Else
Disp "MATRIX"


List vs. (Non-square) Matrix

If Ans is a square matrix, it cannot be distinguished from a list.

Code:
If max(ΔList({1,1}dim(Ans:Then
Disp "NON-SQUARE MATRIX"
Else
Disp "LIST OR SQUARE MATRIX"


List vs. Matrix (small-ish dimension)

The number of elements in Ans must be less than 500 (if a list) or less than 200 (if a matrix).

Code:
If max(ΔList({1,1}dim(Ans))+ΔList({1,1}dim(augment(Ans,Ans:Then
Disp "MATRIX"
Else
Disp "LIST"


Ways to fill in the missing comparisons (e.g. String vs. Matrix) are more than welcome.
Check if a list is complex

This routine can determine if a list in Ans is complex, even if it none of its values have nonzero imaginary components. This can occur in any list where a complex value is stored and subsequently removed. Since lists are homogenous, a single complex value will upcast the entire list; the list will remain complex until it is cleared.

The underlying behavior (sorting a complex list) was brought to my attention by clevor, though its almost certain that others have observed and even relied on it.

Code:
not(real(min(augment(Ans,{0,~1
Sorting a complex list is bizarre. Even Zeroko thought it shouldn't be possible.
These were very helpful in optimizing some of my old programs for better speed and less space! Thanks to all who have posted these ideas. Smile

Code:
(y-1)X+x

I came up with this a long time ago, it finds the right character in a string from x and y coords. I use strings to store maps by stacking the levels of the string. Such as in basic this is how I would stack them:

Code:

"ooooHooooooooooo
Ans+"BBBBBBBBBBBBBBBB->Str1

However once we stack them, picking them apart so you can use it as a map is... weird, to say the least...

Code:

5->x
16->X                                        //X is the max X size of the map. in this case it's 16
1->y
Disp sub(Str1,(y-1)X+x,1)               //x and y are the coordinates of the character you want

For example this algorithm will display "H" to the screen from Str1 which was set above.

The use for this can be to print single characters from the map and even use the map itself as a wall matrix. So I could display the full map using Output and then save precious processing power by not re-rendering the entire map.
Reverse any real integer (using math)
Inputs: X
Output: N


Code:
DelVar NWhile X
10(N+fPart(.1X->N
iPart(.1X->X
End


by Michael2_3B & kg583
Michael2_3B wrote:
Reverse any real integer (using math)
Inputs: X
Output: N


Code:
DelVar NWhile X
10(N+fPart(.1X->N
iPart(.1X->X
End


by Michael2_3B & kg583


This is faster for the same number of bytes (and X is not destroyed)

Inputs: X
Output: Ans


Code:
0
For(N,0,log(X
10Ans+int(10fPart(X10^^(~N-1
End

And as usual, if you're on a color calc, you can replace the 10s with BLUEs to make it faster (the difference is negligible)

Code:
0
For(N,0,log(X
BLUEAns+int(BLUEfPart(X10^^(~N-1
End
String To Matrix
Input: Ans=a string where the first two positions contain the number of columns, the third and fourth positions the number of rows, and the rest is single-digit numeric data
Output: [A]
Destroys: A,B,C,D,[A],Str1
This is SourceCoder code.

Code:
Ans->Str1
expr(sub(Str1,1,2->A
expr(sub(Str1,3,2->B
{A,B->dim([A]
sub(Str1,5,length(Str1)-4->Str1
For(C,1,A
   For(D,1,B
      expr(sub(Str1,D+BC-B,1->[A](C,D
   End
End

Note: This is not designed to be used on maps! Use Output( for that.
I thought I'd try a shot at a more speed-optimized version of that string to matrix routine, because why not?

It satisfies the same inputs, outputs, and destroyed variables. Perhaps it could be optimized further if it used another matrix variable as a temporary, but I found this a fun limitation.

SourceCoder 3 (C) wrote:
:Ans->Str1
:expr(sub(Ans,1,2))-1->A
:expr(sub(Str1,3,2->B
:14iPart((Ans-1)/14->C
:B-Ans->D
:10^(9-Ans+cumSum(not(DeltaList(binompdf(Ans,0
:List>matr(Ans,[A]:[A]^^T
:List>matr(seq(expr(sub(Str1,BI+C+5,D)),I,0,A),[A]
:[A]Ans
:For(D,C-9,5,~14
: List>matr(seq(expr(sub(Str1,BI+D,14)),I,0,A),[A]
: augment([A][[|E~5,|E~4,|E~3,|E~2,.1,1,10,|E2,|E3,|E4,|E5,|E6,|E7,|E8]],Ans
:End
:iPart(10fPart(Ans|E~9->[A]


The basic approach of this method was to extract up to 14 digits from the string at a time (the maximum that could fit into a TI float) and put each group of ≤14 digits into a row of a single-column matrix. Then, that matrix is multiplied by a single-row matrix with increasing powers of 10, producing a rectangular matrix where each row corresponds to one of the groups of digits, with each column shifted by a different number of decimal places.

The groups of digits are processed from right to left, with the "remainder" digits on the right processed first, then full groups of 14 going left, prepending columns to the full matrix using augment(). Fortunately, List>matr() does not affect Ans, so the full matrix could be safely processed using it.

Finally, a single digit is extracted from each matrix cell at the end, using fPart() and iPart().

Edit: I should probably mention that my testing on a 20x20 matrix was approximately 3.5x the speed of the above routine.

Edit 2: Changed the DeltaList logic to remove an unnecessary division.
Input:String
Output: Contrasted text, white text on a small black background around it.

Code:

ClrDraw
AxesOff
FnOff
Prompt X,Y
Input "", Str0
length(Str0→L
Text(-1,Y,X,Str0
For(A,X-1,(x+6L)-1
For(B,Y-1,Y+7)
Pxl-Change(B,A)
End
End
Why didn't I notice this sooner?

I was working on my rouge like a while back and found I was struggling to optimize the code for speed. It was a nightmare, until I realized that MATHPRINT mode is doesn't like it when programs are fast.
Whenever you are coding a program, make most of it in MATHPRINT mode, then after you have optimized for speed make SURE to put CLASSIC ( [catalogue]>[C]>[enter] ) at the beginning of your code.

MATHPRINT mode tells the calculator to display things like fractions as they are written on paper, (aka one on top of the other.) CLASSIC disables this and speeds up display to the home screen by about 3 times.

By coding for speed in MATHPRINT mode you squeeze as much performance out of your code as possible, then CLASSIC basically turns on the turbo boost.
Not sure why nobody mentioned this before, but here it is.
  
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
» Goto page Previous  1, 2, 3 ... 13, 14, 15
» View previous topic :: View next topic  
Page 15 of 15
» All times are UTC - 5 Hours
 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

 

Advertisement