나는 이렇게 학습한다/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))]))