Law of cosines - triples: Difference between revisions

Added R.
(→‎{{header|Phix}}: added syntax colouring the hard way)
(Added R.)
Line 2,045:
60 degrees - uneven triangles of maximum side 10000. Total:
18394</pre>
 
=={{header|R}}==
This looks a bit messy, but it really pays off when you see how nicely the output prints.
<lang R>inputs <- cbind(combn(1:13, 2), rbind(seq_len(13), seq_len(13)))
inputs <- cbind(A = inputs[1, ], B = inputs[2, ])[sort.list(inputs[1, ]),]
Pythagoras <- inputs[, "A"]^2 + inputs[, "B"]^2
AtimesB <- inputs[, "A"] * inputs[, "B"]
CValues <- sqrt(cbind("C (90º)" = Pythagoras,
"C (60º)" = Pythagoras - AtimesB,
"C (120º)" = Pythagoras + AtimesB))
CValues[!t(apply(CValues, MARGIN = 1, function(x) x %in% 1:13))] <- NA
output <- cbind(inputs, CValues)[!apply(CValues, MARGIN = 1, function(x) all(is.na(x))),]
rownames(output) <- paste0("Solution ", seq_len(nrow(output)), ":")
print(output, na.print = "")
cat("There are",
sum(!is.na(output[, 3])), "solutions in the 90º case,",
sum(!is.na(output[, 4])), "solutions in the 60º case, and",
sum(!is.na(output[, 5])), "solutions in the 120º case.")</lang>
{{out}}
<pre> A B C (90º) C (60º) C (120º)
Solution 1: 1 1 1
Solution 2: 2 2 2
Solution 3: 3 4 5
Solution 4: 3 5 7
Solution 5: 3 8 7
Solution 6: 3 3 3
Solution 7: 4 4 4
Solution 8: 5 8 7
Solution 9: 5 12 13
Solution 10: 5 5 5
Solution 11: 6 8 10
Solution 12: 6 6 6
Solution 13: 7 8 13
Solution 14: 7 7 7
Solution 15: 8 8 8
Solution 16: 9 9 9
Solution 17: 10 10 10
Solution 18: 11 11 11
Solution 19: 12 12 12
Solution 20: 13 13 13
There are 3 solutions in the 90º case, 15 solutions in the 60º case, and 2 solutions in the 120º case.</pre>
 
=={{header|Raku}}==
331

edits