-
-
Save Mellen/3391d91803c72a66f9f0fb3ebf87bb39 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function(inp) | |
{ | |
let gbits = ''; | |
const width = 12; | |
inp = inp.replaceAll('\n', ''); | |
let ones = [0,0,0,0,0,0,0,0,0,0,0,0]; | |
let zeros = [0,0,0,0,0,0,0,0,0,0,0,0]; | |
for(let index = 0; index < inp.length; index++) | |
{ | |
let x = index % width; | |
if(inp[index] == '1') | |
{ | |
ones[x]++; | |
} | |
else | |
{ | |
zeros[x]++; | |
} | |
} | |
for(let i = 0; i < width; i++) | |
{ | |
if(ones[i] > zeros[i]) | |
{ | |
gbits += '1'; | |
} | |
else | |
{ | |
gbits += '0'; | |
} | |
} | |
let gamma = parseInt(gbits, 2); | |
let epsilon = gamma ^ 0b111111111111; | |
return epsilon * gamma; | |
})(document.querySelector('pre').innerHTML); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment