山羊与汽车游戏的实验算法

实验1:

function shuffle(target) {var j, x, i = target.length;for (; i > 0; j = parseInt(Math.random() * i), x = target[--i], target[i] = target[j], target[j] = x) {}return target
}function removeAt(target, index) {return !!target.splice(index, 1).length
}var bingo1 = 0
var bingo2 = 0for (var i = 0; i < 10000; i++) {var arr = shuffle([0, 0, 1]);var index = parseInt(Math.random() * 3);if (arr[index]) bingo1++
}for (var i = 0; i < 10000; i++) {var arr = shuffle([0, 0, 1]);var index = parseInt(Math.random() * 3);var errIndex = 0// 主持人删掉一个错误答案for (var j = 0; j < arr.length; j++) {if (arr[j] == 0 && j != index) {errIndex = jarr[j] = 'x'break;}}
   // 遍历所有答案,如果用户选择的是错的,那根据强制交换的约定,就是一定是对的。
for (var k = 0; k < arr.length; k++) {if (arr[k] == 0 && k == index) {bingo2++}} }console.log(bingo1, bingo2);

 

更简单的实验:

function shuffle(target) {var j, x, i = target.length;for (; i > 0; j = parseInt(Math.random() * i), x = target[--i], target[i] = target[j], target[j] = x) {}return target
}function removeAt(target, index) {return !!target.splice(index, 1).length
}var bingo1 = 0
var bingo2 = 0for (var i = 0; i < 10000; i++) {var arr = shuffle([0, 0, 1]);var index = parseInt(Math.random() * 3);if (arr[index]) bingo1++if (!arr[index]) bingo2++
}console.log(bingo1, bingo2);

 

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/390332.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

selenium模块

selenium模块 阅读目录 一 介绍二 安装三 基本使用四 选择器五 等待元素被加载六 元素交互操作七 其他八 项目练习一 介绍 selenium最初是一个自动化测试工具,而爬虫中使用它主要是为了解决requests无法直接执行JavaScript代码的问题selenium本质是通过驱动浏览器&#xff0c;完…

关闭iphone来电mac_如何在Mac和iPhone上关闭通用剪贴板切换(以及为什么要禁用此功能)

关闭iphone来电macIm about to tell you something that will shock you, and probably make you very angry. I hope you wont hate me for it. Here goes.我正要告诉您一些令您震惊的事情&#xff0c;并可能使您非常生气。 我希望你不会为此而恨我。 开始。 If you are an i…

关于tomcat Post 数据参数的问题

2019独角兽企业重金招聘Python工程师标准>>> POST请求本身并未限制传入参数大小&#xff0c;是tomcat 容器设置了接收参数大小的限制。修改server.xml <Connector port"8080" protocol"HTTP/1.1" connectionTimeout"2000" red…

iOS:通信录(完成)(18-01-18更)

1、读取通信录 1&#xff09;、9.0以前&#xff1a;AddressBook 2&#xff09;、9.0以后&#xff1a;Contacts 2、调用通信录UI&#xff08;不弄&#xff09; 1&#xff09;、9.0以前&#xff1a;AddressBookUI 2&#xff09;、9.0以后&#xff1a;ContactsUI 3、参考 0、写在前…

如何在React Native和Firebase中设置Google登录

Google sign-in is a great login feature to offer to your apps users. It makes it easier for them to create an account and sign in. Google登录是一项出色的登录功能&#xff0c;可为您的应用程序用户提供。 这使他们更容易创建帐户并登录。 And whats even better, F…

设计模式-发布订阅模式

这段时间在看vue的双向绑定原理&#xff0c;知道了vue的核心三大件&#xff1a;Observer, Complie, Watcher。 Observer用于监听属性的变化&#xff0c;如有变动就通知 Watcher。 Compile负责解析元素节点的指令&#xff0c;如v-if&#xff0c;v-bind之类, 进行数据和回调函数的…

杜教筛--51nod1239 欧拉函数之和

求$\sum_{i1}^{n}\varphi (i)$&#xff0c;$n\leqslant 1e10$。 这里先把杜教筛的一般套路贴一下&#xff1a; 要求$S(n)\sum_{i1}^{n}f(i)$&#xff0c;而现在有一数论函数$g(i)$&#xff0c;$g(i)$的前缀和很无脑&#xff0c;且$f$和$g$的狄利克雷卷积的前缀和很无脑&#xf…

【Android Studio安装部署系列】目录

概述 从刚开始使用Android Studio到现在&#xff0c;下面所有目录下的操作&#xff0c;当时习惯性的把每一个整理成一个文档&#xff08;其实就是简单文字描述截图&#xff09;&#xff1b;有些地方当时是一知半解&#xff0c;现在会稍微明白一些。正好赶上现在有时间。所以就想…

修改npm全局安装模式的路径

修改npm全局安装模式的路径 在正式写此文章之前&#xff0c;我得说一点血泪史。 刚学nodeJS不久&#xff0c;很纳闷为什么全局安装的模块在 node安装目录/node_modules‘ 中没找到&#xff01;后来仔细看了下安装成功后的信息&#xff0c;才发现原来是自动安装在C盘了&#xff…

javascript创建类_如何使用JavaScript创建吹气效果

javascript创建类Have you ever wondered how you can create a realistic air blowing effect with JavaScript? Like the one shown on the evening TV shows, where multiple balls are being mixed up in a sphere-like object by leveraging air pressure? If you want …

Bootstrap 4:如何使顶部固定的Navbar保持在容器中而不拉伸?

There are many ways to make a fixed navbar stay inside a parents div container. Well go over the most straightforward one here.有很多方法可以使固定的导航栏停留在父级的div容器中。 我们将在这里介绍最简单的方法。 Imagine you have the following code, modified…

基于SpringBoot+Mybatis+Thymeleaf商品信息管理系统

github地址&#xff1a;github.com/zaiyunduan1…,如果对你有帮助&#xff0c;欢迎Star 主要用到的技术&#xff1a; 使用maven进行项目构建使用SpringbootMybatis搭建整个系统使用Thymeleaf模板技术实现页面静态化使用框架Bootstrap、JQuery开发前端界面使用MySQL和MongoDB分别…

在Mac上为自己手动编译安装一套PHP7的开发环境

首先你得去官网下载php7 beta1的版本 这里由于我是在mac上安装&#xff0c;所以就去下载linux相关的版本&#xff0c;地址也直接附上了php7 beta1windows版的官方也有发布详情猛戳&#xff1a;这里 解压安装包&#xff0c;进入源代码目录 tar -zxvf php-7.0.0beta1.tar.gz cd p…

卡特兰数 HDU2067 HDU4165 HDU1134

题目链接&#xff1a;https://vjudge.net/problem/HDU-2067 小兔的棋盘 Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 11800 Accepted Submission(s): 5952 Problem Description小兔的叔叔从外面旅游回来给她…

Python的用途是什么? Python编程语言有10多种编码用途。

&#x1f44b;欢迎 (&#x1f44b; Welcome) Hi! Please take a moment to think about this question: 嗨&#xff01; 请花一点时间考虑这个问题&#xff1a; How is Python applied in real-world scenarios? Python如何在实际场景中应用&#xff1f; If you are learnin…

Publish/Subscribe

Publish/Subscribe 我们将会投递一个消息给多个消费者&#xff0c;这种模式被称为“publish/subscribe” 通俗的讲&#xff0c;前面的是点对点队列模型&#xff0c;现在讲的是发布订阅模型。 Exchanges producer&#xff1a;一个发送消息的用户应用程序 queue&#xff1a;一个存…

[转]在ROS下使用zeroconf配置多机通信

原文地址&#xff1a;http://www.corvin.cn/635.html&#xff0c;转载主要方便随时查阅&#xff0c;如有版权要求&#xff0c;请及时联系。 0x00 为何需要配置ROS多机通信 众所周知ROS是分布式系统&#xff0c;因此可以将机器人需要处理的复杂、计算量大的任务分解在多台机器上…

python中斐波那契数列_斐波那契数列–在Python,JavaScript,C ++,Java和Swift中进行了解释...

python中斐波那契数列by Pau Pavn通过保罗帕文(PauPavn) The Fibonacci sequence is, by definition, the integer sequence in which every number after the first two is the sum of the two preceding numbers. To simplify:根据定义&#xff0c;斐波那契数列是整数序列&a…

1583. 统计不开心的朋友

1583. 统计不开心的朋友 给你一份 n 位朋友的亲近程度列表&#xff0c;其中 n 总是 偶数 。 对每位朋友 i&#xff0c;preferences[i] 包含一份 按亲近程度从高到低排列 的朋友列表。换句话说&#xff0c;排在列表前面的朋友与 i 的亲近程度比排在列表后面的朋友更高。每个列…

uva 247(floyd传递闭包)

为什么&#xff0c;逗号后面&#xff0c;还有空格........ #include <iostream> #include <cstring> #include <algorithm> #include <cstdio> #include <vector> #include <map> using namespace std; const int maxn50; int d[maxn][max…