Law of cosines - triples: Difference between revisions

→‎{{header|Ruby}}: added extra credit
(→‎{{header|Ruby}}: added extra credit)
Line 1,409:
For an angle of 120 there are 2 solutions:
[[3, 5, 7], [7, 8, 13]]
</pre>
Extra credit:
<lang ruby>n = 10_000
ar = (1..n).to_a
squares = {}
ar.each{|i| squares[i*i] = true }
count = ar.combination(2).count{|a,b| squares.key?(a*a + b*b - a*b)}
 
puts "There are #{count} 60° triangles with unequal sides of max size #{n}."
</lang>
{{out}}
<pre>There are 18394 60° triangles with unequal sides of max size 10000.
 
</pre>
1,149

edits