zlacker

[parent] [thread] 0 comments
1. SamRei+(OP)[view] [source] 2019-11-11 09:37:54
One fun enhancement to this is to avoid the n^2 cost it faces with large integers.

    def digit_length(n):
        totlen = 0
        n += not n
        while n > 0:
            klen = 1
            k = 10
            while n > k * k:
                k = k * k
                klen *= 2
            n = n // k
            totlen += klen
        return totlen
[go to top]