Data commit

This commit is contained in:
Ingy döt Net 2023-07-01 11:58:00 -04:00
parent 7387c8f97b
commit cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions

View file

@ -0,0 +1 @@
const std = @import("std");

View file

@ -0,0 +1,14 @@
pub fn main() !void {
const stdout = std.io.getStdOut().writer();
_ = try stdout.writeAll("Police Sanitation Fire\n");
_ = try stdout.writeAll("------ ---------- ----\n");
var p: usize = 2;
while (p <= 7) : (p += 2)
for (1..7 + 1) |s|
for (1..7 + 1) |f|
if (p != s and s != f and f != p and p + f + s == 12) {
_ = try stdout.print(" {d} {d} {d}\n", .{ p, s, f });
};
}

View file

@ -0,0 +1 @@
const std = @import("std");

View file

@ -0,0 +1,14 @@
pub fn main() !void {
const stdout = std.io.getStdOut().writer();
_ = try stdout.writeAll("Police Sanitation Fire\n");
_ = try stdout.writeAll("------ ---------- ----\n");
var it = SolutionIterator{};
while (it.next()) |solution| {
_ = try stdout.print(
" {d} {d} {d}\n",
.{ solution.police, solution.sanitation, solution.fire },
);
}
}

View file

@ -0,0 +1,32 @@
const SolutionIterator = struct {
// 5 bit unsigned (u5) allows addition up to 31
p: u5 = 2,
s: u5 = 1,
f: u5 = 0,
/// 3 bit unsigned (u3) limits 0 <= department <= 7
fn next(self: *SolutionIterator) ?struct { police: u3, sanitation: u3, fire: u3 } {
if (self.p > 7) return null; // already completed
while (true) {
self.f += 1; // fire
if (self.f > 7) {
self.f = 1;
self.s += 1; // sanitation
if (self.s > 7) {
self.s = 1;
self.p += 2; // police
if (self.p > 7) {
return null; // completed
}
}
}
if (self.p + self.f + self.s == 12)
return .{
.police = @truncate(self.p),
.sanitation = @truncate(self.s),
.fire = @truncate(self.f),
};
}
}
};