Catalan numbers/Pascal's triangle: Difference between revisions
Content added Content deleted
(add RPL - fast, idiomatic) |
Recombinant (talk | contribs) m (→{{header|Zig}}: Correct stdout. Add hyperlink to AKS primality task. Comment on comptime const pascal.) |
||
Line 2,346: | Line 2,346: | ||
1 2 5 14 42 132 429 1430 4862 16796 58786 208012 742900 2674440 9694845 </pre> |
1 2 5 14 42 132 429 1430 4862 16796 58786 208012 742900 2674440 9694845 </pre> |
||
=={{header|Zig}}== |
=={{header|Zig}}== |
||
Uses comptime functionality to compile Pascal's triangle into the object code, then at runtime, it's simply a table lookup. (uses code from AKS primality task.) |
Uses comptime functionality to compile Pascal's triangle into the object code, then at runtime, it's simply a table lookup. (uses code from [[AKS test for primes|AKS primality task]].) |
||
<syntaxhighlight lang="zig"> |
<syntaxhighlight lang="zig"> |
||
const std = @import("std"); |
const std = @import("std"); |
||
⚫ | |||
pub fn main() !void { |
pub fn main() !void { |
||
⚫ | |||
var n: u32 = 1; |
var n: u32 = 1; |
||
while (n <= 15) : (n += 1) { |
while (n <= 15) : (n += 1) { |
||
Line 2,370: | Line 2,371: | ||
const rmax = 68; |
const rmax = 68; |
||
// evaluated and created at compile-time |
|||
const pascal = build: { |
const pascal = build: { |
||
@setEvalBranchQuota(100_000); |
@setEvalBranchQuota(100_000); |
||
Line 2,409: | Line 2,411: | ||
15 9694845 |
15 9694845 |
||
</pre> |
</pre> |
||
=={{header|zkl}}== |
=={{header|zkl}}== |
||
{{trans|PARI/GP}} using binomial coefficients. |
{{trans|PARI/GP}} using binomial coefficients. |