Skip welcome & menu and move to editor
Welcome to JS Bin
Load cached copy from
 
<!DOCTYPE html>
<html>
  <head>
<script src="http://cdnjs.cloudflare.com/ajax/libs/prefixfree/1.0.7/prefixfree.min.js"></script>
    <meta charset="utf-8">
    <title>JS Bin</title>
  </head>
  <body>
    <input type="number" id="numberInput" value="8">
    <p id="timeOutput"></p>
    <p id="resultOutput"></p>
    <script id="workerCode" type="javascript/worker">
      self.onmessage = function(e){
        var n = Number(e.data);        
        var m = n + 1;
        var o = [];
        var popCount = function(n){
          for(var x = 0; n; x++) {
            n &= n - 1;
          }
          return x;
        };
        var popCountFast = function(bits) {
          var SK5  = 0x55555555,
              SK3  = 0x33333333,
              SKF0 = 0x0f0f0f0f,
              SKFF = 0xff00ff;
          bits -= (bits >> 1) & SK5;
          bits  = (bits & SK3) + ((bits >> 2) & SK3);
          bits  = (bits & SKF0) + ((bits >> 4) & SKF0);
          bits += bits >> 8;
    
          return (bits + (bits >> 15)) & 63;
        };
        for(var S = 0; S < (1 << n + m - 1); S += 2){
          for(var F = 0; F < (1 << n - 1); F += 1){
            for (var i = 0; i < m; i++){
              var c = popCountFast(((S >> i) & ((1 << n) - 1)) ^ F);
              if(c == n >> 1){
                if(!o[i]) o[i] = 0;
                o[i] += 4;
              } else break;
            }
          }
        }
        self.postMessage(JSON.stringify(o));
      };
    </script>
  </body>
</html>
 
// noprotect
var calculate = function(){
  timeOutput.textContent = 'Calculating...';
  resultOutput.textContent = '';
  resultOutput.className = 'loader';
  var start = new Date();
  var blob = new Blob([workerCode.textContent], {type: 'text/javascript'});
  var worker = new Worker(window.URL.createObjectURL(blob));
  worker.onmessage = function(e){
    resultOutput.className = '';
    resultOutput.textContent = e.data;
    var end = new Date();
    timeOutput.textContent = (end - start)/1000 + ' seconds';
  };  
  worker.postMessage(numberInput.value);
};
numberInput.addEventListener('change',calculate);
calculate();
Output 300px

You can jump to the latest bin by adding /latest to your URL

Dismiss x
public
Bin info
rafaelcastrocoutopro
0viewers