2024-10-24 13:22:59 +02:00
|
|
|
const std = @import("std");
|
2024-10-27 00:16:29 +02:00
|
|
|
|
2024-10-24 13:22:59 +02:00
|
|
|
|
|
|
|
const Timestamp = struct {
|
|
|
|
hours: u64,
|
|
|
|
minutes: u64,
|
|
|
|
};
|
|
|
|
|
2024-10-24 15:02:23 +02:00
|
|
|
const testees:[]const []const u8 = &[_][] const u8 {
|
2024-10-27 13:11:03 +01:00
|
|
|
"Gruppe A",
|
|
|
|
"Gruppe B",
|
|
|
|
"Gruppe C",
|
|
|
|
"Gruppe D",
|
|
|
|
"Gruppe E",
|
|
|
|
"Gruppe F",
|
|
|
|
"Gruppe G",
|
|
|
|
"Gruppe H",
|
|
|
|
"Gruppe I",
|
|
|
|
"Gruppe J",
|
2024-10-24 15:02:23 +02:00
|
|
|
};
|
2024-10-27 13:20:47 +01:00
|
|
|
const number_of_testees: u64 = testees.len;
|
2024-10-25 04:53:24 +02:00
|
|
|
|
2024-10-27 13:20:47 +01:00
|
|
|
const total_minutes: u64 = 190;
|
|
|
|
const pause_minutes: u64 = 5;
|
2024-10-24 13:22:59 +02:00
|
|
|
|
|
|
|
|
|
|
|
pub fn main () !void {
|
2024-10-27 00:16:29 +02:00
|
|
|
|
2024-10-27 13:11:03 +01:00
|
|
|
var time = Timestamp {
|
|
|
|
.hours = 12,
|
|
|
|
.minutes = 0,
|
2024-10-24 13:22:59 +02:00
|
|
|
};
|
|
|
|
|
2024-10-27 13:11:03 +01:00
|
|
|
try printPlan(&time);
|
2024-10-24 13:22:59 +02:00
|
|
|
}
|
|
|
|
|
2024-10-27 13:11:03 +01:00
|
|
|
|
|
|
|
//? Printet timestamp im Format HH:MM
|
2024-10-24 13:22:59 +02:00
|
|
|
pub fn printTimestamp(ts: *Timestamp) !void {
|
2024-10-27 00:16:29 +02:00
|
|
|
|
2024-10-27 13:11:03 +01:00
|
|
|
const writer = std.io.getStdOut().writer();
|
|
|
|
|
2024-10-27 00:16:29 +02:00
|
|
|
try writer.print("{0d:0>2}:{1d:0>2}", .{ ts.hours, ts.minutes });
|
|
|
|
}
|
|
|
|
|
2024-10-27 13:11:03 +01:00
|
|
|
|
|
|
|
//? Add a given minute amount to the given timestamp
|
|
|
|
pub fn addMinutesToTimestamp(ts: *Timestamp, min: u16) void{
|
2024-10-27 00:16:29 +02:00
|
|
|
|
|
|
|
var addHours: u64 = min / 60;
|
|
|
|
var addMinutes: u64 = min%60;
|
|
|
|
|
|
|
|
if ((addMinutes + ts.minutes) >= 60){
|
|
|
|
addMinutes = (addMinutes + ts.minutes)%60;
|
|
|
|
addHours += 1;
|
2024-10-27 00:44:48 +02:00
|
|
|
ts.minutes = 0;
|
2024-10-27 00:16:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
ts.hours += addHours;
|
2024-10-27 00:44:48 +02:00
|
|
|
ts.minutes += addMinutes;
|
2024-10-24 13:22:59 +02:00
|
|
|
}
|
2024-10-25 04:53:24 +02:00
|
|
|
|
2024-10-27 13:11:03 +01:00
|
|
|
|
|
|
|
//? Print the whole test-plan
|
|
|
|
pub fn printPlan(ts: *Timestamp) !void {
|
2024-10-27 00:16:29 +02:00
|
|
|
|
2024-10-25 04:53:24 +02:00
|
|
|
const rand = std.crypto.random;
|
2024-10-27 13:11:03 +01:00
|
|
|
const writer = std.io.getStdOut().writer();
|
|
|
|
|
|
|
|
//? BLOCK CALCULATION
|
|
|
|
const testTime: u64 = total_minutes - ((number_of_testees - 1) * pause_minutes);
|
|
|
|
|
|
|
|
const timePerTest: u64 = testTime / number_of_testees;
|
|
|
|
|
|
|
|
|
|
|
|
//? CREATE RANDOM ORDER ARRAY
|
2024-10-25 04:53:24 +02:00
|
|
|
const noneNumber:u64 = number_of_testees+1;
|
2024-10-27 13:11:03 +01:00
|
|
|
var testees_order: [number_of_testees]u64 = undefined;
|
|
|
|
|
|
|
|
//? Fill order array with noneNumber
|
2024-10-25 04:53:24 +02:00
|
|
|
for (testees_order, 0..) |_, index| {
|
|
|
|
testees_order[index] = noneNumber;
|
|
|
|
}
|
2024-10-27 13:11:03 +01:00
|
|
|
|
|
|
|
//? Fill order array with order until full
|
2024-10-25 04:53:24 +02:00
|
|
|
for (testees, 0..) |_, blockIndex| {
|
|
|
|
while(true) {
|
2024-10-27 13:11:03 +01:00
|
|
|
const randIndex:u64 = rand.intRangeLessThan(u64, 0, number_of_testees);
|
2024-10-25 04:53:24 +02:00
|
|
|
|
|
|
|
if (arrayContains(&testees_order, randIndex)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
testees_order[blockIndex] = randIndex;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2024-10-27 13:11:03 +01:00
|
|
|
|
|
|
|
|
|
|
|
//? PLAN OUTPUT
|
|
|
|
try writer.print("{d} Gruppen x {d} Minuten ({d} Minuten Pause dazwischen) \n", .{number_of_testees, timePerTest, pause_minutes});
|
|
|
|
try writer.print("Beginn des Testat-Termins: ", .{});
|
|
|
|
try printTimestamp(ts);
|
|
|
|
try writer.print("\n", .{});
|
|
|
|
try writer.print("Testat-Bloecke: \n", .{});
|
|
|
|
|
|
|
|
for (testees_order, 0..) |testee, index| {
|
|
|
|
try writer.print("{d}.) ", .{index+1});
|
|
|
|
try printTimestamp(ts);
|
|
|
|
try writer.print("-", .{});
|
|
|
|
addMinutesToTimestamp(ts, timePerTest);
|
|
|
|
try printTimestamp(ts);
|
|
|
|
addMinutesToTimestamp(ts, pause_minutes);
|
|
|
|
try writer.print(": {s} \n", .{testees[testee]});
|
2024-10-25 04:53:24 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-10-27 13:20:47 +01:00
|
|
|
//? Check if a given array contains a given element
|
2024-10-27 13:11:03 +01:00
|
|
|
pub fn arrayContains(arr: []u64, q: u64) bool {
|
2024-10-25 04:53:24 +02:00
|
|
|
for (arr) |element| {
|
|
|
|
if (element == q) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|