So, I was wondering, what's the most optimized version of the pythagorean theorem program in basic, where you can input 'x' for one of the variables? Like, say, you didn't know what A was, so you type in X instead.
Swoll_Monkey wrote:
So, I was wondering, what's the most optimized version of the pythagorean theorem program in basic, where you can input 'x' for one of the variables? Like, say, you didn't know what A was, so you type in X instead.
How about something like this?


Code:
:Disp "A²+B²=C²
:Disp "ENTER 0 FOR UNSURE
:Prompt A,B,C
:If not(A+B)*not(B+C)*not(C+A
:Then:Disp "TOO MANY UNKNOWNS
:Else:If not(A
:Disp("A=",sqrt(C²-B²
:If not(B
:Disp("B=",sqrt(C²-A²
:If not(C
:Disp("C=",sqrt(A²+B²
:End
Sweet! It works, thanks! I couldn't think of how to do it. Probably because I'm not really familiar with the commands.
Smaller

Code:

rand→X
Prompt A,B,C
If A=X
C²-B²
If B=X
C²-A²
If C=X
A²+B²
Disp √(Ans

Tiniest I could make.
noahbaby94 wrote:
Smaller

Code:

rand→X
Prompt A,B,C
If A=X
C²-B²
If B=X
C²-A²
If C=X
A²+B²
Disp √(Ans

Tiniest I could make.


Cool, this works too! But I have a question on what the Rand function does?
generates a random number between 0 and 1
Rand generates a random fraction between 0 and 1, such as 0.394832456 or 0.932958454. He uses it there to make it extremely unlikely the user would inadvertently enter the "flag" value (the rand or X value).
of course, 0->X would be better, since 0 is an impossible value to solve for (or at lease a pointless one!) and it would take much less processor time and power than calculating a rand.
jbr wrote:
of course, 0->X would be better, since 0 is an impossible value to solve for (or at lease a pointless one!) and it would take much less processor time and power than calculating a rand.
And hence Delvar X would be even better. Smile Here, this is my best attempt.


Code:
:Prompt A,B,C
:Disp √(not(A)(C²-B²)+not(B)(C²-A²)+not(C)(A²+B²
KermMartian wrote:
Here, this is my best attempt.


Code:
:Prompt A,B,C
:Disp √(not(A)(C²-B²)+not(B)(C²-A²)+not(C)(A²+B²


optimization never ends =D


Code:

:Prompt A,B,C
:C²-B²-A²
:Disp √(Ans(1-(notC


And yes, I used Ans because placing "C²-B²-A²" in the Disp would require two parenthesis, as opposed to one "Ans"...
Here, save one more byte:


Code:
:Prompt A,B,C
:C²-B²-A²
:Disp √(Ans-Ansnot(C


Your method is genius though, nicely done.
One last optimization....


Code:

:Prompt A,B,C
:C²-B²-A²
:√(Ans-2Ansnot(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