okay so I wanted to make an update of my old refraction program in hybrid-basic, because the old one was just ewh, so I did that and well it is working as it should, but it's soooo slow (mostly the input thing), I don't think it's worth uploading to the archives at that speed even though it's much prettier than the one that I currently have up there. I was wondering if anybody could think of ways to make it better/faster? Anyways here's the code for the whole thing Smile
edit: Okay, I fixed the places where there were two branches that converged to the same place, and added all the ends to the if conditions that were lacking one (that I could find) updated the code below too (already looks much better)

Code:
:DCS
"5255555555555555552555555555555555525555555555555555255555555555555552555555555555555525555555555555555255555555555555552555555588888888828888888888888882888888888888888828888888888888882888888888888888828888888888888882888888888888888828888888888888882888
If 80>det([[20
Then
Disp "Get Doors CSE to run this
Return:End
Degree:Func
DelVar MDelVar LDelVar JDelVar IDelVar V80->N:60->O:80->P:60->Q:60->H:224->T
"01=/02=/n1=/n2=/Crit=->Str2
Lbl 2
DelVar Areal(0,1,1
real(0,3,4,7
real(7,9,0,60,160,60,16
real(7,5,80,0,80,107,31
real(7,7,0,107,160,13,151
real(7,5,80,60,N,O,T
real(7,5,80,60,P,Q,T
real(7,5,80,60,E,H,T
60->H
Str2
real(6,0,3,63,T,47
For(F,1,4
expr(sub("MLIJ",F,1->U
round(U,2->U
8F+55->E
{0,1->L1
{0,U->L2
LinReg(ax+b) {Y1}
Equ>String({Y1},Str0
sub(Str0,1,length(Str0)-3
real(6,0,28,E,T
real(7,5,30F,107,30F,120,151
End
If I>=J:Then
round(V,2->V
{0,1->L1
{0,V->L2
LinReg(ax+b) {Y1}
Equ>String({Y1},Str0
sub(Str0,1,length(Str0)-3
real(6,0,44,95,T
End
If I<J:Then
"none
real(6,0,44,95,T
End
real(7,9,90,2,61,21,8
"REFRACT/Mr.Womp
real(6,0,93,5,13,47
real(6,0,92,4,31,47
real(7,7,90,2,61,21,31
"n1  n2  01
real(6,0,5,110,151
"02 Quit
real(6,0,98,110,151
real(7,5,0,60,160,60,31,1
Repeat max(K={11,12,13,14,15,45
getKey->K
End
If K=15 or K=45:Return
5+4(2(K=12)-(K=13)+(K=11->theta
" ->Str5
real(0,3,4,16
sub(Str2,theta,3
real(6,0,45,50,224
"CLEAR:ERASE/ENTER:LOCK IN
real(6,0,5,99,224,47
real(7,7,2,2,156,116,30
real(7,7,0,0,160,120,30,1
While K!=105
Repeat K=45 or K>71 and min(K!={75,81,85,91,95,104
getKey->K
End
If K=45:Then
" ->Str5
real(7,9,68,50,88,15,16,1
End
If K!=105:Then
sub("789  456  123  0.",K-36-5int(.1K),1->Str3
Str5+Str3->Str5
real(8,1,0
Str5
real(6,0,60,50,224,1
End
End
"LOADING...
real(6,0,36,40,224,1
sub(Str5,2,length(Str5)-1->Str5
expr(Str5->C
If theta=1:Then:C->M
DelVar O80-60tan(M->N
End
If theta=5:Then:C->L
80+60tan(L->P
106->Q
End
If theta=9:C->I
If theta=13:C->J
If IJMV and M>V:Then
DelVar H80+(60sin(M)/sin(90-M->E
Goto 2
End
If IJM:Then
sin^-1(Isin(M)/J->L
80+(60sin(L)/sin(90-L->P
106->Q
End
If IJL:Then
sin^-1(Jsin(L)/I->M
DelVar O80-(60sin(M)/sin(90-M->N
End
If IML
Isin(M)/sin(L->J
If JML
Jsin(L)/sin(M->I
If IJ and I>J
sin^-1(J/I->V
Goto 2
Okay okay okay.

This code.. Not going to work.

1: If you use an If:Then, you need an End.
2: If you use an If:Then, you never use a Goto to escape it
3: If you only need to do one thing after a conditional check, you don't need Then



Code:
If M<10:Then:38->F:Goto KJ
Else:If M>=10:Then:46->F
Lbl KJ


to


Code:
If M<10:38->F
If M>=10:46->F


No need for a goto, as the code is going that way anyways.

Any time the calculator comes across a Goto, it starts the program over from the top and scans the program until it finds the corresponding Lbl.

Let us know what you have after you make some of these changes.
In cases like that where the two branches of a conditional simply assign different values to the same variable, you can use something like this:

Code:
38+8(M>9→F


But yeah, at the very least, the conditionals definitely need cleaning up to use End's. Right now, your program is leaking tons of memory and should slow down over time and eventually crash.
Runer112 wrote:
In cases like that where the two branches of a conditional simply assign different values to the same variable, you can use something like this:

Code:
38+8(M>9→F


But yeah, at the very least, the conditionals definitely need cleaning up to use End's. Right now, your program is leaking tons of memory and should slow down over time and eventually crash.

I am going through the code fixing these and I am wondering, if there are more than two branches of a conditional that assign different values to the same variable, like this

Code:
If K=15 or K=45:Then:Stop
Else:If K=13:Then:1->theta:Goto C
Else:If K=12:Then:13->theta:Goto C
Else:If K=11:Then:9->theta:Goto C
Else:5->theta
Lbl C

could the same technique be used, and if so, how?
mr womp womp wrote:
Runer112 wrote:
In cases like that where the two branches of a conditional simply assign different values to the same variable, you can use something like this:

Code:
38+8(M>9→F


But yeah, at the very least, the conditionals definitely need cleaning up to use End's. Right now, your program is leaking tons of memory and should slow down over time and eventually crash.

I am going through the code fixing these and I am wondering, if there are more than two branches of a conditional that assign different values to the same variable, like this

Code:
If K=15 or K=45:Then:Stop
Else:If K=13:Then:1->theta:Goto C
Else:If K=12:Then:13->theta:Goto C
Else:If K=11:Then:9->theta:Goto C
Else:5->theta
Lbl C

could the same technique be used, and if so, how?

This is how I'd do it:

Code:

If K=15 or K=45:Return
5-4(K=13)+8(K=12)+4(K=11)→θ

Return is better than stop in most cases, because it will bring you back to the shell you ran the program in.
If K=13, then it does 5-4, which is 1. If K=12, it does 5+8, which is 13. If K=11, it does 5+4, which is 9. If K doesn't equal any of those, then it just stores 5 to theta.
All of the Thens and Elses can be omitted because there are only one line codes after the conditionals. Plus, the Lbl/Goto can be omitted by moving the 5->θ higher. So,

Code:
If K=15 or K=45:Then:Stop
Else:If K=13:Then:1→theta:Goto C
Else:If K=12:Then:13→theta:Goto C
Else:If K=11:Then:9→theta:Goto C
Else:5→theta
Lbl C

can be

Code:
If K=15 or K=45:Stop
5→θ
If K=13:1→θ
If K=12:13→θ
If K=11:9→θ


However, if you want to combine all of these statements into one expression, you can use the following:


Code:
5-4(K=13)+8(K=12)+4(K=11→θ


This can be optimized further by factoring out a 4.


Code:
5+4(2(K=12)-(K=13)+(K=11→θ
Exactly what does this program do? I have a feeling you can get this under 250 bytes if you rewrite it.
lirtosiast wrote:
Exactly what does this program do? I have a feeling you can get this under 250 bytes if you rewrite it.

this program just solves the refraction formula (finds the missing variable, once 3 are entered) and yeah i'm sure it could be very small, but I also want it to display whats happening to a beam of light Under these circumstances... and it also check for the crit angle, if it finds one it will indicate what it is, and if your incident angle is bigger than this angle, it will bounce off as it would irl... its basically a very complete program for a fairly simple thing, besides, by the time these people are done looking at it, it will be optimised down to 0.5 bytes
Electromagnet8 wrote:


This can be optimized further by factoring out a 4.


Code:
5+4(2(K=12)-(K=13)+(K=11→θ

I did that, It's not in the new code, but it's done Smile
Bump, changed a few things in the code and updated the code in the first post, if anyone thinks of any optimizations that could be brought to the prog, please tell me so I can make these changes and make the prog better Smile
It looks like you're using the LinReg method to convert numbers to strings; since you're using libraries anyway you may as well use the built-in det(1,num) command to convert a float to a string.
lirtosiast wrote:
It looks like you're using the LinReg method to convert numbers to strings; since you're using libraries anyway you may as well use the built-in det(1,num) command to convert a float to a string.

hmmm I thought this feature was only available to monochrome calcs, I'll try it out, what string will it be stored in, since it isn't in the args...
I actually don't know if it works with color calcs, since I don't own one myself; I just assumed all monochrome features were also available in color. Sorry about that...
There is no reason why any non-graphical-oriented command from monochrome calcs should have been removed on color ones. If anything, it's the opposite.
DJ_O wrote:
There is no reason why any non-graphical-oriented command from monochrome calcs should have been removed on color ones. If anything, it's the opposite.

I know, maybe it is available, its because there is no mention of storing vars to strings in the sdk, but either way, idk how to use it xD
DJ_O, lirtosiast, mr womp womp: The NumString function was not carried over from Doors CS to Doors CSE, because the former offers the Celtic III libraries (among others), while the latter offers a fixed and optimized version of the Celtic 2 libraries.

mr womp womp: Further optimization: none of these statements requires the Then and End, because they're conditionals with a single conditionally-executed statement:
Code:
If IML:Then
Isin(M)/sin(L->J
End
If JML:Then
Jsin(L)/sin(M->I
End
If IJ and I>J:Then
sin^-1(J/I->V
End
KermMartian wrote:
DJ_O, lirtosiast, mr womp womp: The NumString function was not carried over from Doors CS to Doors CSE, because the former offers the Celtic III libraries (among others), while the latter offers a fixed and optimized version of the Celtic 2 libraries.

mr womp womp: Further optimization: none of these statements requires the Then and End, because they're conditionals with a single conditionally-executed statement:
Code:
If IML:Then
Isin(M)/sin(L->J
End
If JML:Then
Jsin(L)/sin(M->I
End
If IJ and I>J:Then
sin^-1(J/I->V
End

Fixed this, there used to be more statements in between those conditions, when those were removed, I didn't notice the thens and ends were no longer needed.

Code:
Lbl A
Repeat Ans=45 or Ans>71 and min(Ans!={75,81,85,91,95,104
getKey
End
If Ans!=45 and Ans!=105:Then
sub("789  456  123  0.",Ans-36-5int(.1Ans),1->Str3
Str5+Str3->Str5
real(8,1,0
Str5
real(6,0,60,50,224,1
Goto A
End
If Ans=45:Then:" ->Str5
real(7,9,68,50,88,15,16,1
Goto A
End
Else
"LOADING...
real(6,0,36,40,224,1
sub(Str5,2,length(Str5)-1->Str5
expr(Str5->C

In this code, I believe the Gotos cause a memory leak since they leave an if statement before the end, just wondering if this can be fixed using a while loop like this, to have a loop in a loop basically.

Code:
While K!=105
Repeat K=45 or K>71 and min(K!={75,81,85,91,95,104
getKey->K
End
If K=45:Then
" ->Str5
real(7,9,68,50,88,15,16,1
End
If K!=105:Then
sub("789  456  123  0.",K-36-5int(.1K),1->Str3
Str5+Str3->Str5
real(8,1,0
Str5
real(6,0,60,50,224,1
End
End
"LOADING...
real(6,0,36,40,224,1
sub(Str5,2,length(Str5)-1->Str5
expr(Str5->C
  
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
Page 1 of 1
» 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