Here we have:


Code:
       L2(3)
  L1(2) / \ L1(1)
      /     \
L2(1)---------L2(2)
       L1(3)


L1 holds sides. L2 holds angles. Of the six elements, there should be three zeroes representing three unknowns—no more, no less. The program below will compute the missing sides and angles in addition to the triangle's area. It will display both sets of solutions if two exist (per the SSA theorem), and it will give no output if there are no valid solutions.


Code:
PROGRAM:TRISOLVE
:Degree
:not(L1)(L2+not(L2)(180-sum(L2           //AAS→ASA
:max(L1)sin(Ans)/sin(sum(Ans+min(L1      //Compute sides via ASA
:If 2=sum(not(Ans                        //Did it work?
:√(sum(L1²)-prod(L1+2not(L1)cos(max(L2   //If not, use SAS instead
:If min(L1) or max(L1 and L2)≠sum(not(L1 //It wasn't SSA, right?
:Then
:Goto 0                                  //If not, go ahead to display
:End
:For(X,-1,1,2                            //SSA members only
:max(L1not(L2
:Anscos(L2)+X√(L1²-Ans²sin(L2)²
:max(Ansnot(not(L2
:Lbl 0                                   //Ready to update "sides" list and display
:L1+Ansnot(L1→X
:If min(real(Ansnot(imag(Ans             //Is this solution valid for a triangle?
:Then
:Pause Ans                               //Sides, angles
:Pause cos‾¹(Ans/prod(Ans)(.5sum(Ans²)-Ans²
:sum(.5{L}X
:Pause √(Ansprod(Ans-{L}X                //Area (Heron's formula)
:End
:End


Two problems with this:
  1. It's over 200 bytes – not worth removing the elegant "area" code over.
  2. The SSS case lists the solution twice. A condition needs tightening. (Edit: Fixed)
Any thoughts on streamlining the code a little more? And no, that's not a memory leak.

(Good grief, there's only one store arrow in the entire program, and it only serves as an optimization!)
Good lord, that's elegant. Far be it from me to optimize your BASIC code, Weregoose, and even a bit of staring has utterly failed to produce anything new to optimize. Also, I'm loving what Prettify does to that code.
Suffice it to say that there were a couple issues. The updated version is now on my website and calls for the same manner of input as a regression.
Weregoose wrote:
Suffice it to say that there were a couple issues. The updated version is now on my website and calls for the same manner of input as a regression.
Thanks for sharing, I'll give it a look. It's also great that your site is back.
*speechless over how this is going to help him in geometry*
  
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