Skip to content

Instantly share code, notes, and snippets.

@goofballLogic
Last active November 24, 2025 20:24
Show Gist options
  • Select an option

  • Save goofballLogic/0464e9385456ce8c91d6981e18847f1d to your computer and use it in GitHub Desktop.

Select an option

Save goofballLogic/0464e9385456ce8c91d6981e18847f1d to your computer and use it in GitHub Desktop.
Cassidoo Nov 17 2025
function repeatedIntegers_0(n) {
    const ret = []; 
    for(let i = 0; i <= n; i++)
        ret.push(...String(i).repeat(i).split("").map(i => Number(i)));
    return ret;
}
function* repeatedIntegers_1(n) {
    let i = 0;
    while(++i <= n)
        yield String(i).repeat(i).split("").map(i => Number(i));
}
function repeatedIntegers_2(n) {
    const ret = [];
    const ensure_xs = x => {
        while(ret.filter(y => y === x).length < x) ret.push(x);
    };
    for(let i = 1; i <= n; i++) ensure_xs(i);
    return ret;
}
function repeatedIntegers_3(n) {
    return n < 1 ? [] : repeatedIntegers_3(n-1).concat(Array(n).fill(n));
}
const repeatedIntegers = n => n < 1
    ? []
    : repeatedIntegers(n - 1).concat(Array(n).fill(n));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment