# Figuring out Integer Depth in Python

0
7
Adv1

Adv2

## The problem#

The depth of an integer n is outlined to be what number of multiples of n it’s essential to compute earlier than all 10 digits have appeared at the very least as soon as in some a number of.

Instance:

let see n=42

A number of         worth         digits     remark
42*1              42            2,4
42*2              84             8         4 existed
42*3              126           1,6        2 existed
42*4              168            -         all existed
42*5              210            0         2,1 existed
42*6              252            5         2 existed
42*7              294            9         2,4 existed
42*8              336            3         6 existed
42*9              378            7         3,8 existed

Wanting on the above desk below digits column yow will discover all of the digits from “ to 9, Therefore it required 9 multiples of 42 to get all of the digits. So the depth of 42 is 9. Write a operate named computeDepth which computes the depth of its integer argument. Solely constructive numbers larger than zero shall be handed as an enter.

## The answer in Python code#

Choice 1:

def compute_depth(n):
i = 0
digits = set()
whereas len(digits) < 10:
i += 1
digits.replace(str(n * i))
return i

Choice 2:

def compute_depth(n):
s, i = set(str(n)), 1
whereas len(s) < 10:
i += 1
s |= set(str(n*i))
return i

Choice 3:

from itertools import depend

def compute_depth(n):
discovered = set()
replace = discovered.replace
return subsequent(i for i,x in enumerate(depend(n, n), 1) if replace(str(x)) or len(discovered) == 10)

## Check circumstances to validate our answer#

take a look at.it("Fundamental checks")
take a look at.assert_equals(compute_depth(1),10)
take a look at.assert_equals(compute_depth(42),9)
Adv3