AKS test for primes: Difference between revisions

m
→‎{{header|Zig}}: fix (stdout not comptime on every platform)
imported>Maxima enthusiast
No edit summary
m (→‎{{header|Zig}}: fix (stdout not comptime on every platform))
Line 5,996:
const std = @import("std");
const assert = std.debug.assert;
const stdout = std.io.getStdOut().writer();
 
pub fn main() !void {
const stdout = std.io.getStdOut().writer();
 
var i: u6 = 0;
while (i < 8) : (i += 1)
try showBinomial(stdout, i);
 
try stdout.print("\nThe primes upto 50 (via AKS) are: ", .{});
Line 6,010 ⟶ 6,011:
}
 
fn showBinomial(writer: anytype, n: u6) !void {
const row = binomial(n).?;
var sign: u8 = '+';
var exp = row.len;
try stdoutwriter.print("(x - 1)^{} =", .{n});
for (row) |coef| {
try stdoutwriter.print(" ", .{});
if (exp != row.len)
try stdoutwriter.print("{c} ", .{sign});
exp -= 1;
if (coef != 1 or exp == 0)
try stdoutwriter.print("{}", .{coef});
if (exp >= 1) {
try stdoutwriter.print("x", .{});
if (exp > 1)
try stdoutwriter.print("^{}", .{exp});
}
sign = if (sign == '+') '-' else '+';
}
try stdoutwriter.print("\n", .{});
}
 
Line 6,050 ⟶ 6,051:
const rmax = 68;
 
// evaluated and created at compile-time
const pascal = build: {
@setEvalBranchQuota(100_000);
59

edits