JSFiddle - React, Tailwind, and code Playground

by Konstantin Cryman

JavaScript

console.log( { test: 0 } );

const computeNextTime = function(){

  const totalCoins = [];
  const coinsStartTrue = 12;
  let coinsTrue = coinsStartTrue;
  for( let i = 0; i < 100; i++ ){
    if( Math.random() > 0.5 && coinsTrue > 0 ){
      totalCoins.push( true );
      coinsTrue--;
    } else {
      totalCoins.push( false );
    }
  }


  for( let nextTry = 0; nextTry < coinsStartTrue; nextTry++ ){
    for( let i = 0; i < totalCoins.length; i++ ){
      for( n = 0; n < i; n++ ){
        totalCoins[ n ] = !totalCoins[ n ];
        totalCoins.push( totalCoins.shift() );
        totalCoins.reverse();
      }
      totalCoins.reverse();
    }
    // console.log( { nextTry, totalCoins: [].concat( totalCoins ) } );
  }

  let coinsTrueFinally = 0;
  for( const nextC of totalCoins ){ if( nextC ){ coinsTrueFinally++; } }
  //console.log( { coinsTrueFinally } );

  let arr1 = [];
  let arr2 = [];
  for( let i = 0; i < totalCoins.length; i++ ){
    const nextC = totalCoins.shift();
    if( i % 2 === 0 ){
      arr1.push( nextC );
    } else {
      arr2.push( nextC );
    }
  }


  for( let nextTry = 0; nextTry < coinsStartTrue; nextTry++ ){
    for( let i = 0; i < arr1.length; i++ ){
      for( n = 0; n < i; n++ ){
        arr1[ n ] = !arr1[ n ];
        arr1.reverse();
      }
      arr1.reverse();
    }
      arr1.reverse();
  }

  for( let nextTry = 0; nextTry < coinsStartTrue; nextTry++ ){
    for( let i = 0; i < arr2.length; i++ ){
      for( n = 0; n < i; n++ ){
        arr2[ n ] = !arr2[ n ];
        arr2.reverse();
      }
      arr2.reverse();
    }
      arr2.reverse();
  }


  let cArr1 = 0;
  for( const nextC of arr1 ){ if( nextC ){ cArr1++; } }
  let cArr2 = 0;
  for( const nextC of arr2 ){ if( nextC ){ cArr2++; } }


	const result = [ cArr1, cArr2 ];

	result.sort( ( a, b ) => { return a - b; } );

	return result;
  
};

const tryCount = 15;
const finallyResult = {};

for( let i = 0; i < tryCount; i++ ){

	const nextResult = computeNextTime();
  const...