Jump to content

Law of cosines - triples: Difference between revisions

Line 338:
18394</pre>
 
=={{header|J}}==
'''Solution:'''
<lang j>load 'trig stats'
RHS=: *: NB. right-hand-side of Cosine Law
LHS=: +/@:*:@] - cos@rfd@[ * 2 * */@] NB. Left-hand-side of Cosine Law
 
solve=: 4 :0
adjsides=. >: 2 combrep y
oppside=. >: i. y
idx=. (RHS oppside) i. x LHS"1 adjsides
adjsides ((#~ idx ~: #) ,. ({~ idx -. #)@]) oppside
)</lang>
'''Example:'''
<lang j> 60 90 120 solve&.> 13
+--------+-------+------+
| 1 1 1|3 4 5|3 5 7|
| 2 2 2|5 12 13|7 8 13|
| 3 3 3|6 8 10| |
| 3 8 7| | |
| 4 4 4| | |
| 5 5 5| | |
| 5 8 7| | |
| 6 6 6| | |
| 7 7 7| | |
| 8 8 8| | |
| 9 9 9| | |
|10 10 10| | |
|11 11 11| | |
|12 12 12| | |
|13 13 13| | |
+--------+-------+------+
60 #@(solve -. _3 ]\ 3 # >:@i.@]) 10000 NB. optional extra credit
18394</lang>
=={{header|JavaScript}}==
<lang JavaScript>(() => {
892

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.