Here's a stab at it. As determined in the comments above, this is a matter of taking each number's base 94 representation and adding 32 and printing the corresponding ASCII characters. That's what the char
function below does. The numbers
generator function iterates from 0 to infinity, and the str
function integer-divides the given number by 94 recursively, concatenating the remainders as characters (per char()
) to produce a string.
function* numbers() {
for (let i = 0;; i++) {
yield str(i);
}
}
function str(i) {
if (i === 0) {
return '';
}
return str(Math.floor(i / 94)) + char(i % 94);
}
function char(i) {
return String.fromCharCode(i+32);
}
const gen = numbers();
setInterval(() => console.log(gen.next().value), 50);
If you'd rather have a single function, it might look like this:
function* numbers() {
for (let i = 0;; i++) {
let d = i;
let s = '';
while (d > 0) {
let r = d % 94;
d = Math.floor(d / 94);
s = String.fromCharCode(r+32) + s;
}
yield s;
}
}
const gen = numbers();
setInterval(() => console.log(gen.next().value), 50);