Skip to content

Instantly share code, notes, and snippets.

@bogdanbiv
Created December 24, 2017 09:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bogdanbiv/5d3b9f44b89ca52ba5cb16990a503ceb to your computer and use it in GitHub Desktop.
Save bogdanbiv/5d3b9f44b89ca52ba5cb16990a503ceb to your computer and use it in GitHub Desktop.
CodeGolf
// https://codegolf.stackexchange.com/questions/151537/alternating-bit-smearing
// CodeGolf - alternating bit smearing over trailing 00 for numbers in base 2
smear = function (num) {
const old = num;
let replaces = 0, remind = num%4===0, supl = 0;
while (remind) {
console.log(remind);
remind?replaces++:0;
num = num/4;
remind = num%4===0;
supl += Math.pow(4, replaces);
}
return old + supl;
}
smear(4);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment