PR3L-TestatSystem-Abgabe1/Testat-Planer.zig

82 lines
1.9 KiB
Zig

const std = @import("std");
const writer = std.io.getStdOut().writer();
const Timestamp = struct {
hours: u64,
minutes: u64,
};
const testees:[]const []const u8 = &[_][] const u8 {
"1",
"2",
"3",
"4",
"5",
"6",
"7",
"8"
};
const number_of_testees: u64 = testees.len; // len von testees
const total_minutes: u64 = 60; // Gesamte Dauer in min
const pause_minutes: u64 = 2; // Länge der Pause zwischen 2 Testaten
pub fn main () !void {
var testStamp = Timestamp {
.hours = 13,
.minutes = 5,
};
try writer.print("Amount tests: {d} \n\n", .{number_of_testees});
try printTimestamp(&testStamp);
try writer.print("\n", .{});
try printPlan();
}
// Printet timestamp im Format HH:MM
pub fn printTimestamp(ts: *Timestamp) !void {
try writer.print("{0d:0>2}:{1d:0>2}", .{ ts.hours, ts.minutes });
}
pub fn printPlan() !void {
const rand = std.crypto.random;
const noneNumber:u64 = number_of_testees+1;
var testees_order: [number_of_testees]u8 = undefined;
// Fill order array with noneNumber
for (testees_order, 0..) |_, index| {
testees_order[index] = noneNumber;
}
// Fill order array with a random order
for (testees, 0..) |_, blockIndex| {
while(true) {
const randIndex:u8 = rand.intRangeLessThan(u8, 0, number_of_testees);
if (arrayContains(&testees_order, randIndex)) {
continue;
}
testees_order[blockIndex] = randIndex;
break;
}
}
for (testees_order, 0..) |elem, index| {
try writer.print("Nr.{d}: {s} \n", .{index, testees[elem]});
}
}
pub fn arrayContains(arr: []u8, q: i64) bool {
for (arr) |element| {
if (element == q) {
return true;
}
}
return false;
}