www.hackerrank.com/challenges/recursive-digit-sum/problem
Recursive Digit Sum | HackerRank
recursively sum all digits in a number until there is only one left
www.hackerrank.com
INPUT : n, k

수 n을 k번 나열했을 때, 각 자리의 합을 재귀적으로 구해 한 자리 수의 답을 출력하는 문제
<My Solution>
k의 영향을 받는 최초의 결과는 n의 각 자리 숫자의 합의 k배
이후 res가 10보다 작아질 때 까지 반복
def superDigit(n, k):
res = sum(list(map(int,str(n))))*k
while res>=10:
res = sum(list(map(int,str(res))))
return res
'HACKERRANK > CODE' 카테고리의 다른 글
[HACKERRANK] - BFS: Shortest Reach in a Graph (0) | 2021.02.07 |
---|---|
[HACKERRANK] - Find the nearest clone (1) | 2021.02.06 |
[HACKERRANK] - Roads and Libraries (0) | 2021.02.04 |
[HACKERRANK] - Crossword Puzzle (0) | 2021.02.04 |
[HACKERRANK] - Recursion: Davis' Staircase (0) | 2021.02.03 |
댓글