Advertisement
HasanRasulov

Dog-flea.html

Nov 12th, 2019
210
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 5 0.89 KB | None | 0 0
  1. <html>
  2.  
  3. <head>Dog-Flea</head>
  4.  
  5. <body>
  6.     <script>
  7.         var INIT_FLEA_A = 20,
  8.             INIT_FLEA_B = 0;
  9.         var dog_a = INIT_FLEA_A,
  10.             dog_b = INIT_FLEA_B;
  11.         var gen = 0;
  12.  
  13.         while (true) {
  14.             var pro = Math.floor(Math.random() * (INIT_FLEA_A - INIT_FLEA_B + 1)) + INIT_FLEA_B;
  15.             if (pro <= dog_a && dog_a > 0) {
  16.                 dog_a--;
  17.                 dog_b++;
  18.             } else if (pro > dog_a && dog_b > 0) {
  19.                dog_a++;
  20.                 dog_b--;
  21.             }
  22.  
  23.             console.log("number of flea on A:" + dog_a + "\tnumber of flea on B:" + dog_b);
  24.             if (dog_a == INIT_FLEA_A && dog_b == INIT_FLEA_B) {
  25.                console.log("the proccess returned to initial state at " + gen + "generation ");
  26.                 break;
  27.             }
  28.             gen++;
  29.         }
  30.     </script>
  31. </body>
  32.  
  33. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement