Compare commits
5 Commits
0f046689c0
...
6739b986ab
Author | SHA1 | Date |
---|---|---|
2wenty1ne | 6739b986ab | |
Anastasia Kisner | 8b75a185a2 | |
Anastasia Kisner | 358b3bf4fc | |
Anastasia Kisner | 140815cca4 | |
Victor Hans-Georg Waitz | f5b0496975 |
|
@ -1,37 +1,125 @@
|
|||
const std = @import("std");
|
||||
|
||||
|
||||
const Timestamp = struct {
|
||||
hours: u64,
|
||||
minutes: u64,
|
||||
};
|
||||
|
||||
const testees:[]const []const u8 = &[_][] const u8 {
|
||||
"Nastja",
|
||||
"Vikkes",
|
||||
"Group 3",
|
||||
"Gruppe A",
|
||||
"Gruppe B",
|
||||
"Gruppe C",
|
||||
"Gruppe D",
|
||||
"Gruppe E",
|
||||
"Gruppe F",
|
||||
"Gruppe G",
|
||||
"Gruppe H",
|
||||
"Gruppe I",
|
||||
"Gruppe J",
|
||||
};
|
||||
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
|
||||
|
||||
const number_of_testees: u64 = testees.len; // len von testees
|
||||
const total_minutes: u64 = 190; // Gesamte Dauer in min
|
||||
const pause_minutes: u64 = 5; // Länge der Pause zwischen 2 Testaten
|
||||
|
||||
|
||||
pub fn main () !void {
|
||||
const writer = std.io.getStdOut().writer();
|
||||
var testStamp = Timestamp {
|
||||
.hours = 13,
|
||||
.minutes = 5,
|
||||
|
||||
var time = Timestamp {
|
||||
.hours = 12,
|
||||
.minutes = 0,
|
||||
};
|
||||
|
||||
try writer.print("Amount tests: {d} \n", .{number_of_testees});
|
||||
for (testees) |row| {
|
||||
try writer.print("Name: {s} \n", .{row});
|
||||
}
|
||||
|
||||
try printTimestamp(&testStamp);
|
||||
try printPlan(&time);
|
||||
}
|
||||
|
||||
// Printet timestamp im Format HH:MM
|
||||
|
||||
//? Printet timestamp im Format HH:MM
|
||||
pub fn printTimestamp(ts: *Timestamp) !void {
|
||||
|
||||
const writer = std.io.getStdOut().writer();
|
||||
try writer.print("{d}:{d}", ts.*);
|
||||
|
||||
try writer.print("{0d:0>2}:{1d:0>2}", .{ ts.hours, ts.minutes });
|
||||
}
|
||||
|
||||
|
||||
//? Add a given minute amount to the given timestamp
|
||||
pub fn addMinutesToTimestamp(ts: *Timestamp, min: u16) void{
|
||||
|
||||
var addHours: u64 = min / 60;
|
||||
var addMinutes: u64 = min%60;
|
||||
|
||||
if ((addMinutes + ts.minutes) >= 60){
|
||||
addMinutes = (addMinutes + ts.minutes)%60;
|
||||
addHours += 1;
|
||||
ts.minutes = 0;
|
||||
}
|
||||
|
||||
ts.hours += addHours;
|
||||
ts.minutes += addMinutes;
|
||||
}
|
||||
|
||||
|
||||
//? Print the whole test-plan
|
||||
pub fn printPlan(ts: *Timestamp) !void {
|
||||
|
||||
const rand = std.crypto.random;
|
||||
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
|
||||
const noneNumber:u64 = number_of_testees+1;
|
||||
var testees_order: [number_of_testees]u64 = undefined;
|
||||
|
||||
//? Fill order array with noneNumber
|
||||
for (testees_order, 0..) |_, index| {
|
||||
testees_order[index] = noneNumber;
|
||||
}
|
||||
|
||||
//? Fill order array with order until full
|
||||
for (testees, 0..) |_, blockIndex| {
|
||||
while(true) {
|
||||
const randIndex:u64 = rand.intRangeLessThan(u64, 0, number_of_testees);
|
||||
|
||||
if (arrayContains(&testees_order, randIndex)) {
|
||||
continue;
|
||||
}
|
||||
testees_order[blockIndex] = randIndex;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//? 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]});
|
||||
}
|
||||
}
|
||||
|
||||
// Check if a given array contains a given element
|
||||
pub fn arrayContains(arr: []u64, q: u64) bool {
|
||||
for (arr) |element| {
|
||||
if (element == q) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue