diff --git a/pfes/sort/.vscode/settings.json b/pfes/sort/.vscode/settings.json new file mode 100644 index 0000000..cbac569 --- /dev/null +++ b/pfes/sort/.vscode/settings.json @@ -0,0 +1,3 @@ +{ + "deno.enable": true +} diff --git a/pfes/sort/deno.json b/pfes/sort/deno.json new file mode 100644 index 0000000..8ce0d8a --- /dev/null +++ b/pfes/sort/deno.json @@ -0,0 +1,6 @@ +{ + "fmt": { + "lineWidth": 120, + "useTabs": true + } +} \ No newline at end of file diff --git a/pfes/sort/input.csv b/pfes/sort/input.csv new file mode 100644 index 0000000..a8e2d8c --- /dev/null +++ b/pfes/sort/input.csv @@ -0,0 +1,25 @@ +alexandre.di-santo +anas.el-khatir 2 5 3 1 4 6 +arnaud.avare +baptiste.mabille +bastien.taur +clement.thollet 2 6 3 1 5 4 +edwin.galibert 1 2 6 5 3 4 +enzo.laik +julia.royer 5 4 1 2 6 3 +loick.balloy +luna.zozor 4 5 1 2 6 3 +matthieu.jolimaitre 6 1 5 4 2 3 +nicolas.bruguet 3 4 2 1 6 5 +nicolas.marc 4 3 2 1 6 5 +noe.bigorre +quentin.de-capele +theo.dedaele 1 2 4 3 6 5 +theo.loret +thomas.didier +valentin.champenois +valentin.giaufer 5 4 3 1 6 2 +vincent.goguyer-lalande 3 5 2 1 6 4 +vincent.guillen +yann.goulvestre 2 6 3 1 5 4 +yannis.breleur 4 5 3 1 6 2 diff --git a/pfes/sort/main.ts b/pfes/sort/main.ts new file mode 100755 index 0000000..47d8153 --- /dev/null +++ b/pfes/sort/main.ts @@ -0,0 +1,49 @@ +#!/bin/env -S deno run -A + +function main() { + const input = read_input("./input.csv"); + + const MAX_IN_GROUP = 4; + const groups = Array.from(range(1, 7)) + .map((sujet_no) => ({ sujet_no, members: [] as { login: string; prio: number }[] })); + + for (const prio of range(1, 7)) { + for (const entry of input) { + if (entry.placed) continue; + for (const [index, choice] of enumerate(entry.choices)) { + if (choice !== prio) continue; + if (groups[index].members.length >= MAX_IN_GROUP) continue; + groups[index].members.push({ login: entry.login, prio }); + entry.placed = true; + } + } + } + + let result = ""; + for (const group of groups) { + const members = group.members.map((item) => `${item.login}(${item.prio})`).join("\t"); + const line = `Sujet ${group.sujet_no}\t${members}`; + result += line + "\n"; + } + Deno.writeTextFileSync("./output.csv", result); +} + +function read_input(path: string) { + const content = Deno.readTextFileSync(path); + const cells = content.split("\n").filter((line) => line !== "").map((line) => line.split("\t")); + const toint = (n: string) => ((parsed) => isNaN(parsed) ? 0 : parsed)(parseInt(n)); + return cells.map(( + [login, s1, s2, s3, s4, s5, s6], + ) => ({ login, choices: ([s1, s2, s3, s4, s5, s6] as const).map(toint), placed: false })); +} + +function* range(from: number, to: number) { + while (from < to) yield from++; +} + +function* enumerate(iterable: Iterable) { + let index = 0; + for (const item of iterable) yield [index++, item] as const; +} + +if (import.meta.main) main(); diff --git a/pfes/sort/output.csv b/pfes/sort/output.csv new file mode 100644 index 0000000..4013edb --- /dev/null +++ b/pfes/sort/output.csv @@ -0,0 +1,6 @@ +Sujet 1 edwin.galibert(1) theo.dedaele(1) yann.goulvestre(2) +Sujet 2 matthieu.jolimaitre(1) +Sujet 3 julia.royer(1) luna.zozor(1) vincent.goguyer-lalande(2) +Sujet 4 anas.el-khatir(1) clement.thollet(1) nicolas.bruguet(1) nicolas.marc(1) +Sujet 5 +Sujet 6 valentin.giaufer(2) yannis.breleur(2)