Finished assignment. Added function to calculate testat length, generate random order and print plan.
parent
8b75a185a2
commit
6739b986ab
|
@ -1,5 +1,4 @@
|
|||
const std = @import("std");
|
||||
const writer = std.io.getStdOut().writer();
|
||||
|
||||
|
||||
const Timestamp = struct {
|
||||
|
@ -8,50 +7,49 @@ const Timestamp = struct {
|
|||
};
|
||||
|
||||
const testees:[]const []const u8 = &[_][] const u8 {
|
||||
"1",
|
||||
"2",
|
||||
"3",
|
||||
"4",
|
||||
"5",
|
||||
"6",
|
||||
"7",
|
||||
"8"
|
||||
"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 {
|
||||
|
||||
var testStamp = Timestamp {
|
||||
.hours = 13,
|
||||
.minutes = 5,
|
||||
var time = Timestamp {
|
||||
.hours = 12,
|
||||
.minutes = 0,
|
||||
};
|
||||
|
||||
try writer.print("Amount tests: {d} \n\n", .{number_of_testees});
|
||||
|
||||
try printTimestamp(&testStamp);
|
||||
try writer.print("\n", .{});
|
||||
try printPlan();
|
||||
|
||||
try addMinutesToTimestamp(&testStamp, 175);
|
||||
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("{0d:0>2}:{1d:0>2}", .{ ts.hours, ts.minutes });
|
||||
}
|
||||
|
||||
pub fn addMinutesToTimestamp(ts: *Timestamp, min: u16) !void{
|
||||
|
||||
//? 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;
|
||||
|
@ -60,27 +58,34 @@ pub fn addMinutesToTimestamp(ts: *Timestamp, min: u16) !void{
|
|||
|
||||
ts.hours += addHours;
|
||||
ts.minutes += addMinutes;
|
||||
|
||||
}
|
||||
|
||||
pub fn printPlan() !void {
|
||||
|
||||
//? 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;
|
||||
|
||||
var testees_order: [number_of_testees]u8 = undefined;
|
||||
|
||||
// Fill order array with noneNumber
|
||||
//? Fill order array with noneNumber
|
||||
for (testees_order, 0..) |_, index| {
|
||||
testees_order[index] = noneNumber;
|
||||
}
|
||||
|
||||
|
||||
// Fill order array with a random order
|
||||
//? Fill order array with order until full
|
||||
for (testees, 0..) |_, blockIndex| {
|
||||
while(true) {
|
||||
const randIndex:u8 = rand.intRangeLessThan(u8, 0, number_of_testees);
|
||||
const randIndex:u64 = rand.intRangeLessThan(u64, 0, number_of_testees);
|
||||
|
||||
if (arrayContains(&testees_order, randIndex)) {
|
||||
continue;
|
||||
|
@ -90,12 +95,27 @@ pub fn printPlan() !void {
|
|||
}
|
||||
}
|
||||
|
||||
for (testees_order, 0..) |elem, index| {
|
||||
try writer.print("Nr.{d}: {s} \n", .{index, testees[elem]});
|
||||
|
||||
//? 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]});
|
||||
}
|
||||
}
|
||||
|
||||
pub fn arrayContains(arr: []u8, q: i64) bool {
|
||||
// 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;
|
||||
|
|
Loading…
Reference in New Issue