코드로 우주평화

Square Every Digit 본문

나는 이렇게 학습한다/Algorithm & SQL

Square Every Digit

daco2020 2022. 4. 18. 21:49
반응형

Description:

Welcome. In this kata, you are asked to square every digit of a number and concatenate them.

For example, if we run 9119 through the function, 811181 will come out, because 92 is 81 and 12 is 1.

Note: The function accepts an integer and returns an integer

 

 

 

Solution:

1. Separate the numbers by one digit.
2. Square each of the separated numbers.
3. Return the squared numbers side by side.

 

def square_digits(num):
    return int(''.join([str(i**2) for i in map(int, str(num))]))

 

반응형

'나는 이렇게 학습한다 > Algorithm & SQL' 카테고리의 다른 글

Remove the minimum  (0) 2022.04.20
Sum of two lowest positive integers  (0) 2022.04.19
Sort Numbers  (0) 2022.04.17
Regex validate PIN code  (0) 2022.04.16
Get the mean of an array  (0) 2022.04.15