I actually wrote this a few days ago and uploaded it to the archives, but was too busy to make a post.
This is a molar mass calculator, for calculating the mass in grams of one mole of a substance.
It supports parenthesis, and you can even nest them.
There is also a silent mode where, if you put a string in Ans, the program will use that rather than prompting the user.
Unfortunately, I haven't found a way to distinguish between a string and a list. Please let me know if there is a way to do this.
Here's the source if anyone wants to obsessively optimize this:
Code:
This is a molar mass calculator, for calculating the mass in grams of one mole of a substance.
It supports parenthesis, and you can even nest them.
There is also a silent mode where, if you put a string in Ans, the program will use that rather than prompting the user.
Unfortunately, I haven't found a way to distinguish between a string and a list. Please let me know if there is a way to do this.
Here's the source if anyone wants to obsessively optimize this:
Code:
DelVar LFor(M,1,1
End
Ans->L
Ans->M
If L=M
Then
Input ":",Str1
Str1+" ->Str1
Else
Ans+" ->Str1
DelVar |LLDelVar |LM
End
{1.00794,4.0026,6.941,9.01218,10.81,12.0111,14.0067,15.9994,18.998403,20.179,22.98977,24.305,26.98154,28.0855,30.97376,32.06,35.453,39.948,39.0983,40.08,44.9559,47.88,50.9415,51.996,54.938,55.847,58.9332,58.69,63.546,65.39,69.72,72.59,74.9216,78.96,79.904,83.8,85.4678,87.62,88.9059,91.224,92.9064,95.94,98,101.07,102.906,106.42,107.868,112.41,114.82,118.71,121.75,127.6,126.905,131.29,132.905,137.33,138.906,140.12,140.908,144.24,145,150.36,151.96,157.25,158.925,162.5,164.93,167.26,168.934,173.04,174.967,178.49,180.948,183.85,186.207,190.2,192.22,195.08,196.967,200.59,204.383,207.2,208.98,209,210,222,223,226.025,227.028,232.038,231.036,238.029,237.048,244,243,247,247,251,252,257,258,259,260,261,262,263,262->L1
length(Str1->L
{0->L2
For(P,1,L-1
If sub(Str1,P,1)="(
Then
1+dim(L2->dim(L2
Else
If sub(Str1,P,1)=")
Then
If 1=dim(L2
Goto C
L2(dim(L2->M
dim(L2)-1->dim(L2
Else
If inString("abcdefghijklmnopqrstuvwxyz",sub(Str1,P+1,1
Then
P+1->P
sub(Str1,P-1,2
Else
sub(Str1,P,1)+"
End
.5(1+inString("H HeLiBeB C N O F NeNaMgAlSiP S ClArK CaScTiV CrMnFeCoNiCuZnGaGeAsSeBrKrRbSrY ZrNbMoTcRuRhPdAgCdInSnSbTeI XeCsBaLaCePrNdPmSmEuGdTbDyHoErTmYbLuHfTaW ReOsIrPtAuHgTlPbBiPoAtRnFrRaAcThPaU NpPuAmCmBkCfEsFmMdNoLr",Ans
If fPart(Ans
Goto C
L1(Ans->M
End
0
While inString("0123456789",sub(Str1,P+1+Ans,1
Ans+1
End
Ans->S
M
If S
Ans*expr(sub(Str1,P+1,S
Ans+L2(dim(L2->L2(dim(L2
P+S->P
End
End
If 1=dim(L2
Goto E
Lbl C
{~1->L2
Lbl E
L2(1