DESCRIPTION:
The depth of an integer n is defined to be how many multiples of n it is necessary to compute before all 10 digits have appeared at least once in some multiple.
example:
let see n=42
Multiple value digits comment
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
Looking at the above table under digits column you can find all the digits from 0 to 9, Hence it required 9 multiples of 42 to get all the digits. So the depth of 42 is 9. Write a function named computeDepth which computes the depth of its integer argument.Only positive numbers greater than zero will be passed as an input.
def compute_depth(n):
ans=[]
j=1
while len(ans)!=10:
for i in sinnum(n*j):
if i not in ans:
ans.append(i)
j+=1
return j-1
def sinnum(n):
temp=[]
for i in str(n):
temp.append(i)
return temp
'알고리즘 문제 > CodeWar' 카테고리의 다른 글
Financing Plan on Planet XY140Z-n (0) | 2022.11.22 |
---|---|
Irreducible Sum of Rationals (0) | 2022.11.22 |
Sort array by string length (0) | 2022.11.21 |
Run-length encoding (1) | 2022.11.20 |
Descending Order (0) | 2022.11.20 |