Humble numbers

func smooth_generator(primes) {

    var s = primes.len.of { [1] }

    {
        var n = s.map { .first }.min
        { |i|
            s[i].shift if (s[i][0] == n)
            s[i] << (n * primes[i])
        } * primes.len
        n
    }
}

with (smooth_generator([2,3,5,7])) {|g|
    say 50.of { g.run }.join(' ')
}

say "\nThe digit counts of humble numbers"
say '═'*35

with (smooth_generator([2,3,5,7])) {|g|
    for (var(d=1,c=0); d <= 20; ++c) {
        var n = g.run
        n.len > d || next
        say "#{'%10s'%c.commify}  have  #{'%2d'%d}  digit#{[:s,''][d==1]}"
        (c, d) = (0, n.len)
    }
}

Output:

Last updated

Was this helpful?