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
  
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