Combinations and permutations: Difference between revisions
m
→{{header|Sidef}}: updated code
(added scheme example) |
m (→{{header|Sidef}}: updated code) |
||
Line 1,570:
=={{header|Sidef}}==
{{trans|Perl 6}}
<lang ruby>func P(n, k) { n! / ((n-k)!) }
func C(n, k) { binomial(n, k) }
class Logarithm(value) {
method to_s {
var e = int(value/10.log)
"%.8fE%+d" % (exp(value - e*10.log), e)
}
}
func lstirling(n) {
n < 10
}
Line 1,594 ⟶ 1,593:
}
say "=> Exact results:"
var p =
say "P(#{n}, #{p}) = #{P(n, p)}"
}
var p =
say "C(#{n}, #{p}) = #{C(n, p)}"
}
say '';
say "=> Floating point approximations:"
for n ([5, 50, 500, 1000, 5000, 15000]
var p =
say "P(#{n}, #{p}) = #{P_approx(n, p)}"
}
var p =
say "C(#{n}, #{p}) = #{C_approx(n, p)}"
}</lang>
{{out}}
|