Skip to content

Instantly share code, notes, and snippets.

@DonMartin76
Created February 13, 2017 07:41
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 DonMartin76/3c61e30f86af40647923c46c3802fa8b to your computer and use it in GitHub Desktop.
Save DonMartin76/3c61e30f86af40647923c46c3802fa8b to your computer and use it in GitHub Desktop.
'use strict';
let i = 2;
let done = false;
while (!done) {
console.log("Checking " + i);
const i3 = i.toString(3);
const i4 = i.toString(4);
const i5 = i.toString(5);
if (hasOnly01(i3) && hasOnly01(i4) && hasOnly01(i5)) {
const i2 = i.toString(2);
console.log("Yay!");
console.log(i2 + ", " + i3 + ", " + i4 + ", " + i5);
done = true;
}
++i;
}
function hasOnly01(s) {
for (let i = 0; i < s.length; ++i) {
if (s[i] != '0' && s[i] != '1')
return false;
}
return true;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment