Guest User

ExoLundi1.hx

a guest
Jun 24th, 2014
388
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Haxe 2.23 KB | None | 0 0
  1. package;
  2.  
  3. // Un élève = un nom, un prénom et une liste de notes
  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"
  25.         ];
  26.  
  27.         var firstname_part2 = [
  28.             "colas", "nnick", "stien", "mon", "va", "main", "belle", "dric", "lia",
  29.             "tor", "noit", "stophe", "trice", "die", "nais",
  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>;
  38.  
  39.         for (i in 0 ... 1000) {
  40.             do {
  41.                 exists    = false;
  42.                 name      = rand_array(names).toUpperCase();
  43.                 firstname = rand_array(firstname_part1) + rand_array(firstname_part2);
  44.                 notes     = new Array<Int>();
  45.  
  46.                 for (i in 0 ... 5) {
  47.                     notes.push(rand(0, 20));
  48.                 }
  49.  
  50.                 for (student in students) {
  51.                     if (name == student.name && firstname == student.firstname) {
  52.                         exists = true;
  53.                         break;
  54.                     }
  55.                 }
  56.             } while (exists);
  57.  
  58.             students.push({
  59.                 name:      name,
  60.                 firstname: firstname,
  61.                 notes:     notes
  62.             });
  63.         }
  64.  
  65.         // Affichage des élèves
  66.         for (student in students) {
  67.             Sys.println('${student.name}, ${student.firstname} ${student.notes.join(" ")}');
  68.         }
  69.  
  70.         // Petite pause
  71.         Sys.stdin().readLine();
  72.     }
  73.  
  74.     // Génération d'un nombre [ min ; max ]
  75.     public static inline function rand(min:Int, max:Int) {
  76.         return Math.floor(Math.random() * (max - min + 1)) + min;
  77.     }
  78.  
  79.     // Récupération d'une valeur aléatoire dans une liste
  80.     public static inline function rand_array(array:Array<String>) {
  81.         return array[rand(0, array.length - 1)];
  82.     }
  83. }
Advertisement
Add Comment
Please, Sign In to add comment