id/email
password
forgot password | create account
about | help | code help+videos | done | prefs
CodingBat code practice

 

peter@norvig.com > powersum
prev  |  next  |  chance

Given k and n, return a list of all the positive integers less than n such that the sum of the kth powers of their individual digits equals the integer itself. For example, with k=3 and n=1000, one of the numbers we would return in the list would be 371, because 371 = 3^3 +7^3 + 1^3 = 27 + 343 + 1. (This problem inspired by Project Euler.)


powersum(1, 10) → [1, 2, 3, 4, 5, 6, 7, 8, 9]
powersum(2, 100) → [1]
powersum(3, 1000) → [1, 153, 370, 371, 407]

...Save, Compile, Run (ctrl-enter)

def powersum(k, n):

Editor font size %:
Shorter output


Forget It! -- delete my code for this problem

Progress graphs:
 Your progress graph for this problem
 Random user progress graph for this problem
 Random Epic Progress Graph

Python Help

Difficulty: 300 Post-solution available

Copyright Nick Parlante 2017 - privacy