Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function getRandomIntInclusive(min, max) {
- min = Math.ceil(min);
- max = Math.floor(max);
- return Math.floor(Math.random() * (max - min + 1)) + min; //Максимум и минимум включаются
- }
- class Paradox {
- constructor() {
- this.doorWithCar = getRandomIntInclusive(0, 2)
- this.playerChose = getRandomIntInclusive(0, 2)
- }
- openTheDoor() {
- let openedDoor
- while(openedDoor !== this.doorWithCar && openedDoor !== this.playerChose) {
- openedDoor = getRandomIntInclusive(0, 2)
- }
- const result = this.result(openedDoor)
- return result
- }
- result(openedDoor) {
- let changedPick = this.changePick(openedDoor);
- if(changedPick === this.doorWithCar) {
- return 1
- }
- if(this.playerChose) {
- return 0
- }
- }
- changePick(openedDoor) {
- let changedPick
- while(changedPick !== openedDoor && changedPick !== this.playerChose) {
- changedPick = getRandomIntInclusive(0, 2)
- }
- return changedPick
- }
- }
- let playerWins = 0
- let changedWins = 0
- for(let i = 0; i < 100000; i++) {
- const game = new Paradox()
- const result = game.openTheDoor()
- if(result === 0){
- playerWins++
- }
- if(result === 1) {
- changedWins++
- }
- }
- console.log('Без изменения выбора: ' + playerWins,'С изменением выбора: ' + changedWins)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement