I found a small program that was released in ticalc.org's last batch of updates, Analogue (sic) Clock. The original code:

BASIC Code wrote:
:PlotsOff
:FnOff
:AxesOff
:Degree
:ClrDraw
:1→Xmin
:95→Xmax
:63→YMax
:1→Ymin
:For(θ,25,28,0.2
:Circle(47,31,θ
:End
:For(θ,0,360,30
:sin(θ→A
:cos(θ→B
:A*25→D
:D+47→D
:B*25→E
:E+31→E
:A*22→F
:F+47→F
:B*22→G
:G+31→G
:Line(D,E,F,G
:End
:getTime→L2
:getTime→L1
:For(A,1,10
:A-1→A
:getTime→L1
:Lbl C
:getTime→L2
:If L1(3)=L2(3
:Goto C
:getTime→L1
:10→C
:L1(1→H
:L1(2→M
:L1(3→S
:M/60→T
:M/60→E
:S/60→N
:S/60→F
:If H>12
:H-12→H
:H/12→U
:T*360→T
:U*360→U
:N*360→N
:E*30→E
:F*6→F
:U+E→U
:T+F→T
:sin(T→X
:cos(T→Z
:sin(U→Q
:cos(U→R
:sin(N→V
:cos(N→W
:20*X→X
:20*Z→Z
:14*Q→Q
:14*R→R
:17*V→V
:17*W→W
:Line(47,31,L3(1)+47,L3(2)+31,0
:Line(47,31,V+47,W+31
:Line(47,31,L3(3)+47,L3(4)+31,0
:Line(47,31,Q+47,R+31
:Line(47,31,L3(5)+47,L3(6)+31,0
:Line(47,31,X+47,Z+31
:Line(46,32,48,32
:Line(46,30,48,30
:Line(46,30,46,32
:Line(48,30,48,32
:V→L3(1
:W→L3(2
:Q→L3(3
:R→L3(4
:X→L3(5
:Z→L3(6
:End
Generated by SourceCoder, © 2005 Cemetech


Horrendous, right? There's no reason for a program to be that long. In fact, this is some of the worst coding I've ever seen. Here's my initial optimization of it; can anyone make it better?

BASIC Code wrote:
:PlotsOff
:FnOff :AxesOff
:Degree :ClrDraw
:1→Xmin:1→deltaX
:1→Ymin:1→deltaY
:For(θ,25,28,.2
:Circle(47,31,θ
:End
:For(θ,0,360,30
:sin(θ→A:cos(θ→B
:Line(25A+47,25B+31,22A+47,22B+31
:End
:getTime→L2
:getTime→L1
:While not(getKey
:While L1(3)=L2(3
:getTime→L2
:End
:L1(1→H
:L1(2→M
:L1(3→S
:M/2+30(H-12(H>12→U
:6M+.1S→T
:Line(47,31,V+47,W+31,0
:Line(47,31,Q+47,R+31,0
:Line(47,31,X+47,Z+31,0
:20sin(T→X
:20cos(T→Z
:14sin(U→Q
:14cos(U→R
:17sin(6S→V
:17cos(6s→W
:Line(47,31,V+47,W+31
:Line(47,31,Q+47,R+31
:Line(47,31,X+47,Z+31
:PtOn(47,31,2
:End
Generated by SourceCoder, © 2005 Cemetech

Code:
:PlotsOff
:FnOff :AxesOff
:Degree
:ZStandard
:ZInteger
:For(θ,25,28,.2
:Circle(0,0,θ
:End
:For(θ,0,11
:sin(30θ→A:cos(30θ→B
:Line(25A,25B,22A,22B
:End
:getTime→L1
:Repeat getKey
:While min(L1=getTime
:End
:L1(1→H
:L1(2→M
:L1(3→S
:6M+.1S→T
:T/12+30H→U
:Line(0,0,V,W,0
:Line(0,0,Q,R,0
:Line(0,0,X,Z,0
:20sin(T→X
:20cos(T→Z
:14sin(U→Q
:14cos(U→R
:17sin(6S→V
:17cos(6S→W
:Line(0,0,V,W
:Line(0,0,Q,R
:Line(0,0,X,Z
:PtOn(0,0,2
:End


I'll work on a faster (but bigger) routine for drawing the clock frame.
Ah, nice use of min in the getTime loop.
this gets slightly off topic but anyways I optimized this quadratic equation solver my friend's teacher wrote...


Code:
:Input"A=",A
:Input"B=",B
:Input"C=",C
:(-B+sqrt(B^2-4AC))/(2A)->D
:(-B-sqrt(B^2-4AC))/(2A)-->E
:Disp D, E


to


Code:
:Prompt A,B,C
:(-B+sqrt(B62-4AC))/(2A)
:Disp Ans, -B/A -A


is there any way to optimize it further?? =D
rthprog wrote:
this gets slightly off topic but anyways I optimized this quadratic equation solver my friend's teacher wrote...


Code:
:Input"A=",A
:Input"B=",B
:Input"C=",C
:(-B+sqrt(B^2-4AC))/(2A)->D
:(-B-sqrt(B^2-4AC))/(2A)-->E
:Disp D, E


to


Code:
:Prompt A,B,C
:(-B+sqrt(B62-4AC))/(2A)
:Disp Ans, -B/A -A


is there any way to optimize it further?? =D
Always Very Happy



Code:
:Prompt A,B,C
:(-B+sqrt(B^2-4AC))/(2A
:Disp Ans, -B/A-Ans


I'm almost Just Joking; all I did was remove a single closing parenthesis. Other than that, you did an excellent job.
  
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