Calculate Scrabble Score of Word
Inputs:
Str1
Output:
Score in Ans



Code:
{1,3,3,2,1,4,2,4,1,8,5,1,3,1,1,3,10,1,1,1,1,4,4,8,4,10→L₁
0
For(A,1,length(Str1
Ans+L₁(inString("ABCDEFGHIJKLMNOPQRSTUVWXYZ",sub(Str1,A,1
End
Decimal to Binary
Input: N = decimal
Output: Ans = 8-bit binary



Code:
2fPart(.5int(N2^seq(X,X,~7,0


I can maybe optimize it even more Smile

EDIT:
Convert Decimal to base <= 10
Inputs: N = decimal
A = base
Output: Ans = 8-bit base-A



Code:
AfPart(1/Aint(NA^seq(X,X,~7,0
Is the title of this thread supposed to say "Userful" or is that a typo on "Useful?"
PT_ wrote:
Decimal to Binary
Input: N = decimal
Output: Ans = 8-bit binary



Code:
2fPart(.5int(N2^seq(X,X,~7,0


I can maybe optimize it even more Smile

EDIT:
Convert Decimal to base <= 10
Inputs: N = decimal
A = base
Output: Ans = 8-bit base-A



Code:
AfPart(1/Aint(NA^seq(X,X,~7,0


I was looking at this to make a little evil number checker, which requires the integer to be expressed in binary. I noticed the first routine could be changed up a little to accomodate integers of any number of bits like this:

Input: N = decimal
Output: Ans = X-bit binary (as many bits as it needs)


Code:
2fPart(.5int(N2^seq(X,X,~int(logBASE(N,2)),0

and since I know logBASE is not available on older calcs, it can of course be done like this as well:

Code:
2fPart(.5int(N2^seq(X,X,~int(log(N)/log(2)),0

Just thought this might be and interesting routine to drop here Razz
For example, if N is chosen to be 255, the routine will output {1,1,1,1,1,1,1,1} (8 bits), but if it is chosen to be 256, it will output {1,0,0,0,0,0,0,0,0} (9 bits)

Code:
15->G
int(10rand(4->L1
While max(Ans
Input A
int(10fPart(A/10^(5-cumSum(1 or L1->L2
L1≠Ans
Disp {sum(Ans and seq(sum(L2=L1(A)),A,1,4)),sum(not(Ans
DS<(G,1
End
If max(Ans
Disp L1
"YOU "+sub("WIN LOSE",1+4max(Ans),4


A short version of the game MasterMind.

Basically, you have to guess a four-digit code.

Code:
int(10rand(4->L1

It generates a random code and stores it in L1.

Code:
Input A

You input your guess as a four-digit number.

Code:
int(10fPart(A/10^(5-cumSum(1 or L1->L2

This line parses your answer, turning a four-digit number into a list and storing it to L2.

Code:
L1≠Ans
Disp {sum(Ans and seq(sum(L2=L1(A)),A,1,4)),sum(not(Ans

This section compares your guess to the correct answer, and gives two numbers: (1) number of digits that are correct and in the wrong place, and (2) number of digits that are correct and in the right place.

Code:
DS<(G,1

Razz I wonder how many people fainted at this infamous command. It seemed easier than the For( loop.
RandomGuest wrote:

Code:

15→G
int(10rand(4→L1
While max(Ans
Input A
int(10fPart(A/10^(5-cumSum(1 or L1→L2
L1≠Ans
Disp {sum(Ans and seq(sum(L2=L1(A)),A,1,4)),sum(not(Ans
DS<(G,1
End
If max(Ans
Disp L1
"YOU "+sub("WIN LOSE",1+4max(Ans),4


Hmmm I see this is some sort of guessing game with 4 integers that you must guess in 15 or less guesses aided by the output of a list of two integers (which I have yet to understand the meaning of) after every input. This is a pretty thick routine, almost looks like it's been golfed. Could you please include a description of what this routine does exactly in your post and maybe a brief explanation of how it works?
I believe there are two bugs in this Mastermind routine. The first is minor: While max(Ans will immediately end the game as a win for the player if 0000 happens to be generated. This is fixed with a change to Repeat not(max(Ans. Secondly, this snippet:

Code:
{sum(Ans and seq(sum(L2=L1(A)),A,1,4)),sum(not(Ans

returns 2 when the code is 0011 and the guess is 1222; if we're going by the Mastermind rules I found on Wikipedia, I believe it should return 1. Here's my attempt:

Code:
sum(seq(min(sum(L1=N),sum(L2=N)),N,0,9))-sum(not(Ans))


That said, the routine is well-optimized. I did find a few improvements.


Code:
int(10rand(4->L1
For(G,~15,~1
Input A
int(10fPart(A/10^(5-cumSum(1 or L1->L2
sum(L1=Ans
Disp {sum(seq(min(sum(L1=N),sum(L2=N)),N,0,9))-Ans,Ans
If Ans<4
End
If not(G
Disp L1
"LOSE
If G
"WIN
"YOU "+Ans


If it were necessary to preserve Ans, 1+4max(Ans) could have been 5^max(Ans). Two more bytes can be saved by using custom list names.

I haven't tested this yet, so it may be wrong.
MateoConLechuga wrote:
Compare Strings

Not sure if this is the best way to do it, but this compares Str1 to Str0.
Inputs:
[Str0] - String 1
[Str1] - String 2

Outputs:
Ans - 1 if same, 0 if not same


Code:
length(Str1)=length(Str0
If Ans
prod(seq(A=inString(Str0,sub(Str1,A,1)),A,1,length(Str1

That is not the best way to do it...

Code:
Str1=Str2
This doesn't seem to be posted here already and it came up over on TI|BD. Lirtosiast found this a while back. Truly amazing.
Code:
PROGRAM:A
prgmB
UnArchive prgmC
prgmC
Archive prgmC

PROGRAM:B
{0->u(nMin)

PROGRAM:C
\\whatever you want

End


prgmA and prgmB need to be unarchived. Running prgmA unarchives, runs, and re-archives prgmC. prgmA works like the home screen and prgmC is a normal program. More info here
The End isn't necessary; as far as I know prgmC has no requirements.

After that I found a somewhat convoluted way to archive and unarchive a program using only one other program:

lirtosiast wrote:

EDIT: This works without the colons!


Code:
PROGRAM:AAAAAAAA
{0->u(nMin)
"..":If π=X:Return:For(X,π,0:End:prgmAAAAAAAA
DelVar X
UnArchive prgmC
prgmC
Archive prgmC


The two dots inside the string are filler characters, which are required because the program name is 8 characters long. For a seven- or six-letter program name, there should be one or zero filler characters instead.
I think I found a bug in the Base N to Base M converter. I plug in a number and if it's less than variable M, then it ERROR: INCREMENTS. This line errors:

Code:
seq(0,A,1,int(log(B)/log(M->L1

If the input in Str1 is equal to M, then the program outputs 1 instead of 10. The numbers 3, 7, 9, 14, 19, 22, 26, 30, 33, and 34 in this case create a never ending loop with the while loop; this is using the input base as any base. It also lets you go past base 36, stored in M (If you store it in N, it gives INVALID DIMENSION like it's supposed to), which I don't understand.
How can this be fixed?
An update to an older post:


Code:
:0
:Repeat 0
:.5Ans+i^int(3rand
:Pt-On(real(Ans),imag(Ans
:End


This draws from -2 to 2 on the x-axis, and 0 to 2 on the y.
RandomGuest wrote:

Code:
15->G
int(10rand(4->L1
While max(Ans
Input A
int(10fPart(A/10^(5-cumSum(1 or L1->L2
L1≠Ans
Disp {sum(Ans and seq(sum(L2=L1(A)),A,1,4)),sum(not(Ans
DS<(G,1
End
If max(Ans
Disp L1
"YOU "+sub("WIN LOSE",1+4max(Ans),4


A short version of the game MasterMind.

Basically, you have to guess a four-digit code.

Code:
int(10rand(4->L1

It generates a random code and stores it in L1.

Code:
Input A

You input your guess as a four-digit number.

Code:
int(10fPart(A/10^(5-cumSum(1 or L1->L2

This line parses your answer, turning a four-digit number into a list and storing it to L2.

Code:
L1≠Ans
Disp {sum(Ans and seq(sum(L2=L1(A)),A,1,4)),sum(not(Ans

This section compares your guess to the correct answer, and gives two numbers: (1) number of digits that are correct and in the wrong place, and (2) number of digits that are correct and in the right place.

Code:
DS<(G,1

Razz I wonder how many people fainted at this infamous command. It seemed easier than the For( loop.


I made my own version a long time ago.


Code:
ClrHome
"?
Disp "NUMBER:","",Ans,Ans,Ans,Ans
Output(8,1,"RED: 0  WHITE: 0
DelVar TDelVar GDelVar Rint(10rand(4→L1
4→dim(L2
Repeat T=14 or K=45 or R=4
Repeat Ans
getKey
End
Ans(102≠Ans)-13int(Ans/13(2>abs(5-abs(5-abs(Ans-83→K
If Ans=105 and G=4
Then
For(X,1,4
Output(2+X,3+T,L2(X
End
DelVar GT+1→T
sum(L1=L2→R
Output(8,6,Ans
Output(8,16,‾Ans+sum(seq(min(sum(L1=X),sum(L2=X)),X,0,9
Output(1,9,"    //4 spaces
Else
If Ans≤9 and G≠4
Then
G+1→G
K→L2(Ans
End
If Ans=24 and G
Then
G-1→G
Output(1,Ans+9," //1 space
End
End
For(X,0,G
If X
Output(1,8+X,L2(X
End
End
For(X,1,4
Output(2+X,1,L1(X
End
If K≠45
Then
Output(1,1,"YOU "+sub("WIN!   LOSE...",8-7(R=4),7
Pause
End
DelVar GDelVar KDelVar RDelVar TDelVar XDelVar L1DelVar L2ClrHome
KermMartian wrote:

Modulo division
Input:
A=Dividend
B=Divisor

Code:

Code:

:Round(BfPart(A/B),0

The Round( is in there in case of an infinitely repeating decimal (like 1/3).
The Tari, Something1990, and Calc84Maniac


remainder() is not faster?
_iPhoenix_ wrote:
KermMartian wrote:

Modulo division
Input:
A=Dividend
B=Divisor

Code:

Code:

:Round(BfPart(A/B),0

The Round( is in there in case of an infinitely repeating decimal (like 1/3).
The Tari, Something1990, and Calc84Maniac


remainder() is not faster?

That routine is from 2006... There was no remainder() command. Also, the speed difference is surely negligible.

JWinslow23 wrote:
Calculate Scrabble Score of Word
Inputs:
Str1
Output:
Score in Ans



Code:
{1,3,3,2,1,4,2,4,1,8,5,1,3,1,1,3,10,1,1,1,1,4,4,8,4,10→L₁
0
For(A,1,length(Str1
Ans+L₁(inString("ABCDEFGHIJKLMNOPQRSTUVWXYZ",sub(Str1,A,1
End


That's a lot of 1s... You could rearrange the letters to group them together.


Code:
augment(binomcdf(9,0),{3,3,2,4,2,4,8,5,3,3,10,4,4,8,4,10→L₁
0
For(A,1,length(Str1
Ans+L₁(inString("AEILNORSTUBCDFGHJKMPQVWXYZ",sub(Str1,A,1
End
So I was mathing yesterday and made a thing...

Riemann Zeta Function
Input: Ans = {x∈ ℝ| x≠1}
Output: Ans = ζ(Ans)


Code:
(2^(Ans-1))/(Ans-1)-2^(Ans)fnInt((sin(Anstan^-1(X)))/((1+X^^2)^(Ans/2)(e^(piX)+1)),X,0,8


This actually converges much faster than the usual , which converges slower and slower as you obtain more decimal places. As a comparison, I tried this:
, which resulted in a 30 second calculation that was accurate to 6 decimal places.
Then I tried plugging 3 into the routine above, and got a 4 second calculation with all 9 displayed digits being accurate.
As we discussed on SAX this won't work well for negative X due to precision issues.

In 2008, trichoplax wrote this routine for Riemann Zeta of complex numbers which I'll link to when I can find it again. I don't completely understand how it works, but it runs in ~1 second for N=17, Z=3+0i at 15MHz.

Z is the argument; N is the accuracy parameter. Sublinear convergence though not as bad as summing the series directly, and it also doesn't work well for Re(Z) < 0.

trichoplax wrote:

Code:
cosh(Nln(3+sqrt(8->C
seq(K,K,1,N->L1
(-1)^Ans*(C-cumSum(N4^Ans/(N+Ans)(N+Ans) nCr (2Ans

C^-1/(2^(1-Z)-1)sum(Ans/L1^Z


Even better, all except the last line can be precomputed. So for one second of precomputation of the 20 coefficients, any number of zeta evaluations can be performed for ~0.1s each.
mr womp womp wrote:

Code:
augment(binomcdf(9,0),{3,3,2,4,2,4,8,5,3,3,10,4,4,8,4,10→L₁
0
For(A,1,length(Str1
Ans+L₁(inString("AEILNORSTUBCDFGHJKMPQVWXYZ",sub(Str1,A,1
End

Sacrificing a little bit of speed, what about this routine for Scrabble score of a word?

Code:
{1,3,3,2,4,2,4,8,5,3,3,10,4,4,8,4,10→L₁
sum(seq(L₁(1+inString("BCDFGHJKMPQVWXYZ",sub(Str1,A,1))),A,1,length(Str1

Or this?

Code:
sum(1+int(10fPart(.06039591e^(seq(inString("GKBCQFM HVDJZWPXY",sub(Str1,X,1)),X,1,length(Str1
11 years ago, thornahawk μολών λαβέ posted this gamma function routine.
As you may know, the gamma function can be used to compute the Beta function using this form: . Therefore, you can modify the gamma function routine to compute like this:

Code:
{P,Q,P+Q→L2
For(D,1,3
L2(D→A
A→Z
If 0>real(A
1-Z→Z
e^((Z-.5)ln(Z+8.5)-Z-8.5+ln(√(2π)(1+sum({5716.4001882743,-14815.304267684,14291.492776575,-6348.1602176415,1301.6082860583,-108.17670535144,2.6056965056118,-0.0074234525,5.384136 × 10^-8,-4.02353 × 10^-9}/(Z-1+cumSum(binomcdf(9,0
If 0>real(A
2πi/Ans/(2isin(πA
augment(L2,{Ans→L2
End
round(Ans(4)Ans(5)/Ans(6),8
mr womp womp wrote:
ln(√( )
i/Ans/(e^(-πiA

τ. Razz

I even took a look at the Lanczos approximation, the actual place that first guy got the gamma function formula, and guess what it consists of?


where


One more image from the Mathworld page on it:


All 2πs. No πs.
  
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 ... 11, 12, 13, 14, 15  Next
» View previous topic :: View next topic  
Page 12 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