Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <html>
- <head>Dog-Flea</head>
- <body>
- <script>
- var INIT_FLEA_A = 20,
- INIT_FLEA_B = 0;
- var dog_a = INIT_FLEA_A,
- dog_b = INIT_FLEA_B;
- var gen = 0;
- while (true) {
- var pro = Math.floor(Math.random() * (INIT_FLEA_A - INIT_FLEA_B + 1)) + INIT_FLEA_B;
- if (pro <= dog_a && dog_a > 0) {
- dog_a--;
- dog_b++;
- } else if (pro > dog_a && dog_b > 0) {
- dog_a++;
- dog_b--;
- }
- console.log("number of flea on A:" + dog_a + "\tnumber of flea on B:" + dog_b);
- if (dog_a == INIT_FLEA_A && dog_b == INIT_FLEA_B) {
- console.log("the proccess returned to initial state at " + gen + "generation ");
- break;
- }
- gen++;
- }
- </script>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement