Created
December 24, 2017 09:06
-
-
Save bogdanbiv/5d3b9f44b89ca52ba5cb16990a503ceb to your computer and use it in GitHub Desktop.
CodeGolf
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
// 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