SHOW:
|
|
- or go back to the newest paste.
1 | package; | |
2 | ||
3 | - | // Un élève = un nom, un prénom et une liste de notes |
3 | + | // Un élève = un nom, un prénom et une liste de notes (ils n'ont pas de vies !) |
4 | typedef Student = { name:String, firstname:String, notes:Array<Int> }; | |
5 | ||
6 | class ExoLundi1 { | |
7 | public static function main() { | |
8 | // La liste des élèves | |
9 | var students = new Array<Student>(); | |
10 | ||
11 | // Les noms possibles | |
12 | var names = [ | |
13 | "Martin", "Bernard", "Thomas", "Petit", "Robert", | |
14 | "Richard", "Durand", "Dubois", "Moreau", "Laurent", | |
15 | "Simon", "Michel", "Lefebvre", "Leroy", "Roux", | |
16 | "David", "Bertrand", "Morel", "Fournier", "Girard", | |
17 | "Bonnet", "Dupont", "Lambert", "Fontaine", "Rousseau", | |
18 | "Vincent", "Muller", "Lefevre", "Faure", "Andre" | |
19 | ]; | |
20 | ||
21 | // Les prénoms qui seront générés | |
22 | var firstname_part1 = [ | |
23 | "Ni", "Ya", "Seba", "Si", "Mae", "Ro", "Isa", "Ce", "Ju", | |
24 | - | "Vic", "Be", "Chri", "Bea", "Elo", "A" |
24 | + | "Vic", "Be", "Chri", "Bea", "Elo", "A", "Hu" |
25 | ]; | |
26 | ||
27 | var firstname_part2 = [ | |
28 | "colas", "nnick", "stien", "mon", "va", "main", "belle", "dric", "lia", | |
29 | - | "tor", "noit", "stophe", "trice", "die", "nais", |
29 | + | "tor", "noit", "stophe", "trice", "die", "nais", "go", |
30 | "ger", "lie", "ole" | |
31 | ]; | |
32 | ||
33 | // Génération de 1000 élèves extraordinaires | |
34 | var exists:Bool; | |
35 | var name:String; | |
36 | var firstname:String; | |
37 | - | var notes:Array<Int>; |
37 | + | |
38 | for (i in 0 ... 1000) { | |
39 | do { | |
40 | exists = false; | |
41 | name = rand_array(names).toUpperCase(); | |
42 | firstname = rand_array(firstname_part1) + rand_array(firstname_part2); | |
43 | ||
44 | - | notes = new Array<Int>(); |
44 | + | |
45 | if (name == student.name && firstname == student.firstname) { | |
46 | - | for (i in 0 ... 5) { |
46 | + | |
47 | - | notes.push(rand(0, 20)); |
47 | + | |
48 | } | |
49 | } | |
50 | } while (exists); | |
51 | ||
52 | students.push({ | |
53 | name: name, | |
54 | firstname: firstname, | |
55 | notes: [ for (j in 0 ... 5) rand(0, 20) ] | |
56 | }); | |
57 | } | |
58 | ||
59 | // Affichage des élèves | |
60 | for (student in students) { | |
61 | - | notes: notes |
61 | + | |
62 | } | |
63 | ||
64 | // Petite pause | |
65 | Sys.stdin().readLine(); | |
66 | } | |
67 | ||
68 | // Génération d'un nombre [ min ; max ] | |
69 | public static inline function rand(min:Int, max:Int) { | |
70 | return Math.floor(Math.random() * (max - min + 1)) + min; | |
71 | } | |
72 | ||
73 | // Récupération d'une valeur aléatoire dans une liste | |
74 | public static inline function rand_array(array:Array<String>) { | |
75 | return array[rand(0, array.length - 1)]; | |
76 | } | |
77 | } |