<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
Keyboard Shortcuts
Shortcut | Action |
---|---|
ctrl + [num] | Toggle nth panel |
ctrl + 0 | Close focused panel |
ctrl + enter | Re-render output. If console visible: run JS in console |
Ctrl + l | Clear the console |
ctrl + / | Toggle comment on selected lines |
ctrl + ] | Indents selected lines |
ctrl + [ | Unindents selected lines |
tab | Code complete & Emmet expand |
ctrl + shift + L | Beautify code in active panel |
ctrl + s | Save & lock current Bin from further changes |
ctrl + shift + s | Open the share options |
ctrl + y | Archive Bin |
Complete list of JS Bin shortcuts |
JS Bin URLs
URL | Action |
---|---|
/ | Show the full rendered output. This content will update in real time as it's updated from the /edit url. |
/edit | Edit the current bin |
/watch | Follow a Code Casting session |
/embed | Create an embeddable version of the bin |
/latest | Load the very latest bin (/latest goes in place of the revision) |
/[username]/last | View the last edited bin for this user |
/[username]/last/edit | Edit the last edited bin for this user |
/[username]/last/watch | Follow the Code Casting session for the latest bin for this user |
/quiet | Remove analytics and edit button from rendered output |
.js | Load only the JavaScript for a bin |
.css | Load only the CSS for a bin |
Except for username prefixed urls, the url may start with http://jsbin.com/abc and the url fragments can be added to the url to view it differently. |