JSFiddle - React, Tailwind, and code Playground
JavaScript
var TypicalCoin = function () {};
TypicalCoin.prototype.next = function () {
return Math.round(Math.random());
};
var WrongCoin = function () {
this.staes = [[1, 2, 3, -1], [-1, 3, 2, 1], [2, 1, -1, 3]];
this.stateInd = 0;
this.typicalCoin = new TypicalCoin();
};
WrongCoin.prototype.next = function () {
// only two usage of next
var attemptSum = this.typicalCoin.next() + 2 * this.typicalCoin.next();
if (this.staes[this.stateInd][attemptSum ] === -1) {
this.stateInd = (this.stateInd + 1) % 3
}
return this.staes[this.stateInd][attemptSum];
};
// Test
var testCoin = new WrongCoin(), attempts = [], i;
for (i = 0; i < 10000; i++) {
attempts.push(testCoin.next())
}
var countOf1 = attempts.filter(function (el) {return el == 1;}).length;
var countOf2 = attempts.filter(function (el) {return el == 2;}).length;
var countOf3 = attempts.filter(function (el) {return el == 3;}).length;
alert ([countOf1, countOf2, countOf3].join(' - '));