Skip to content

Instantly share code, notes, and snippets.

@Mellen
Created December 6, 2021 12:11
Show Gist options
  • Save Mellen/3391d91803c72a66f9f0fb3ebf87bb39 to your computer and use it in GitHub Desktop.
Save Mellen/3391d91803c72a66f9f0fb3ebf87bb39 to your computer and use it in GitHub Desktop.
(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