Combinations and permutations: Difference between revisions

m
→‎{{header|R}}: Syntax highlighting.
(Added 11l)
m (→‎{{header|R}}: Syntax highlighting.)
Line 1,997:
=={{header|R}}==
R has most of this built in. The documentation for choose warns that it only calculates its result directly if k is small. Skimming [https://github.com/wch/r-source/blob/trunk/src/nmath/choose.c what appears to be the source code] suggests that 29 is the highest "small" k. This means that we can solve both tasks with little more than R's choose.
<lang rrsplus>perm <- function(n, k) choose(n, k) * factorial(k)
print(perm(seq(from = 3, to = 12, by = 3), seq(from = 2, to = 8, by = 2)))
print(choose(seq(from = 10, to = 60, by = 10), seq(from = 3, to = 18, by = 3)))
Line 2,015:
#R does not have big integers by default and will return Inf without warning.
#R's documentation does not tell us exactly when choose's behaviour changes.
 
=={{header|Racket}}==
 
331

edits