Optimize Challenge
Reply | Flag | Categorize
Timothy Foster 02 Feb 2013 15:57
Timothy Foster

Admin

WAC

Guest

Sometimes, optimization requires more than just squeezing out bytes. Entire sections of code can often be revised into more compact, efficient algorithms.

Discover what this program does and rewrite it for either speed or size.

ClrHome
"?→Str1
Disp "AX²+BX+C=0
Prompt A,B,C
If A<0
Then
‾A→A
‾B→B
‾C→C
End
gcd(A,abs(B
gcd(Ans,abs(C→V
A/Ans→A
B/V→B
C/V→C
For(D,A,1,‾1
If not(fPart(A/D
Then
For(E,abs(C),1,‾1
If not(fPart(C/E
Then
A/D→F
abs(C/E→G
If DAns+FE=B and EG=C
"1D1E1F1G→Str1
If DG-FE=B and ‾EG=C
"1D‾E1F1G→Str1
If FE‾DG=B and ‾EG=C
"1D1E1F‾G→Str1
If ‾DG-FE=B and EG=C
"1D‾E1F‾G→Str1
If DE+FG=B and EG=C
"1D1G1F1E→Str1
If DE-FG=B and ‾EG=C
"1D‾G1F1E→Str1
If FG-DE=B and ‾EG=C
"1D1G1F‾E→Str1
If ‾DE-FG=B and EG=C
"1D‾G1F‾E→Str1
If Str1≠"?
Then
ClrHome
Disp "(AX+B)(CX+D)=0
For(H,1,7,2
Disp expr(sub(Str1,H,2
End
Disp "FACTOR OUT
Output(7,2,V
Return
End
End
End
End
End
ClrHome
Disp "PRIME
Disp "FACTOR OUT
Output(3,2,V

Attachment:

Make a reply:

To use the style buttons, click on the one you want, then press Ctrl+V.


Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-Noncommercial 2.5 License.