pfes
This commit is contained in:
parent
7f1fad4403
commit
a94776695a
5 changed files with 89 additions and 0 deletions
3
pfes/sort/.vscode/settings.json
vendored
Normal file
3
pfes/sort/.vscode/settings.json
vendored
Normal file
|
@ -0,0 +1,3 @@
|
|||
{
|
||||
"deno.enable": true
|
||||
}
|
6
pfes/sort/deno.json
Normal file
6
pfes/sort/deno.json
Normal file
|
@ -0,0 +1,6 @@
|
|||
{
|
||||
"fmt": {
|
||||
"lineWidth": 120,
|
||||
"useTabs": true
|
||||
}
|
||||
}
|
25
pfes/sort/input.csv
Normal file
25
pfes/sort/input.csv
Normal file
|
@ -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
|
|
49
pfes/sort/main.ts
Executable file
49
pfes/sort/main.ts
Executable file
|
@ -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<T>(iterable: Iterable<T>) {
|
||||
let index = 0;
|
||||
for (const item of iterable) yield [index++, item] as const;
|
||||
}
|
||||
|
||||
if (import.meta.main) main();
|
6
pfes/sort/output.csv
Normal file
6
pfes/sort/output.csv
Normal file
|
@ -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)
|
|
Loading…
Add table
Add a link
Reference in a new issue