Inconsummate numbers in base 10

var gen_inconsummate = Enumerator({|callback|

    for n in (1..Inf) {
        for k in (1..Inf) {

            if (9*k*n < 10**(k-1)) {
                callback(n)
                break
            }

            var check = false
            10.combinations_with_repetition(k, {|*d|
                var s = d.sum || next
                if (Str(s*n).sort == d.join) {
                    check = true
                    break
                }
            })
            check || next
            break
        }
    }
})

with (50) {|n|
    say "First #{n} inconsummate numbers (in base 10):"
    gen_inconsummate.first(n).each_slice(10, {|*s|
        say s.map{ '%3s' % _ }.join(' ')
    })
}

Output:

Last updated

Was this helpful?