def test_sum_powers_of_digits(self): self.assertEqual(mathhelper.sum_powers_of_digits(123, 3), 36) self.assertEqual(mathhelper.sum_powers_of_digits(0, 3), 0) self.assertEqual(mathhelper.sum_powers_of_digits(1, 27), 1) self.assertEqual(mathhelper.sum_powers_of_digits(345, 2), 50) self.assertEqual(mathhelper.sum_powers_of_digits(12345, 0), 5) self.assertEqual(mathhelper.sum_powers_of_digits(12345, 1), 15)
def problem30(): """ Digit fifth powers Find the sum of all the numbers that can be written as the sum of fifth powers of their digits. """ return sum(x for x in range(2, (9 ** 6) + 1) if x == mathhelper.sum_powers_of_digits(x, 5))