티스토리 뷰

문제 링크

https://www.codewars.com/kata/take-a-number-and-sum-its-digits-raised-to-the-consecutive-powers-and-dot-dot-dot-eureka/train/python


내 답

def sum_dig_pow(a, b):
list = []
for i in range(a,b+1):
sum = 0
for n,k in enumerate(str(i),1):
sum += int(k)**n
if i == sum:
list.append(i)
return list


득점 많은 답

def dig_pow(n):
return sum(int(x)**y for y,x in enumerate(str(n), 1))

def sum_dig_pow(a, b):
return [x for x in range(a,b + 1) if x == dig_pow(x)]




'개발 > Quiz' 카테고리의 다른 글

[codewars] Pete, the baker  (0) 2017.12.20
[codewars] Sort the odd  (0) 2017.12.17
Complementary DNA  (0) 2017.12.11
Format a string of names like 'Bart, Lisa & Maggie'.  (0) 2017.12.10
Count the number of Duplicates  (0) 2017.12.09
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2024/12   »
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30 31
글 보관함