亘古微博
咨询邮箱:nicholas@anycle.com
您的位置:网站首页 > 新闻动态 > 算法专题 >
[JS] How boys and girls stand balance
来源:未知 作者:admin 发表于:2015-03-03 15:36  点击
This code shows how boys and girls standing balance.


<input type=text name=dis id=dis style="width:500px;" />
<script>
function $(id){
return document.getElementById(id);
}
 
girl = 0;
boy = 0;
people = 0;
 
function fuck(){
  sex = Math.round(Math.random());
  people ++; 
  if(sex > 0){
    boy ++;
  }else{
    girl ++;
    fuck();
  }
}
 
for(i=0; i<100000; i++){
  fuck();
  
}
 
$("dis").value = "girl:"+girl+"  boy:"+boy+"  total:"+people;
 
</script>


Result:
相关文章推荐
[C] Insertion sort

This is the insertion sort function by nicholas....

[C] Binary sort

Just a simple example of binary sort....

[C] Bubble sort

Bubble sort should be avoided in the case of large collections. It will not be ef...

[JS] How boys and girls stand balance

How boys and girls stand balance...