[PYTHON] Project Euler 30

problem

Surprisingly, there are only three numbers where the sum of each digit squared matches the original number.

1634 = 1**4 + 6**4 + 3**4 + 4**4 8208 = 8**4 + 2**4 + 0**4 + 8**4 9474 = 9**4 + 4**4 + 7**4 + 4**4 However, it does not include 1 = 1 ** 4. The sum of these numbers is 1634 + 8208 + 9474 = 19316.

Find the sum of the numbers so that the sum of the numbers raised to the fifth power of each digit matches the original number. http://odz.sakura.ne.jp/projecteuler/index.php?cmd=read&page=Problem%2030

Answer

Wrist exercise.

def main():
  MAX = (9**5)*6+1
  ls = [x**5 for x in range(10)]
  ans = 0
  for num in range(2,MAX):
    wa = sum(map(lambda x: ls[int(x)], str(num)))
    if wa == num:
      ans += num
  print ans
  
main()

Recommended Posts

Project Euler 7
Project Euler 47
Project Euler 31
Project Euler 38
Project Euler 17
Project Euler 8
Project Euler 23
Project Euler 22
Project Euler 19
Project Euler 50
Project Euler 42
Project Euler 32
Project Euler 35
Project Euler 36
Project Euler 46
Project Euler 48
Project Euler 6
Project Euler 44
Project Euler 39
Project Euler 40
Project Euler 49
Project Euler 29
Project Euler 27
Project Euler 41
Project Euler 18
Project Euler 13
Project Euler 30
Project Euler 16
Project Euler 14
Project Euler 34
Project Euler 25
[Project Euler] problem1
Project Euler15 "Lattice Path"
Project Euler Original Method Group 1
What is Project Euler 3 Acceleration?
[Note] Project Euler in Python (Problem 1-22)
Functional programming in Python Project Euler 3
Project Euler # 5 "Minimum Multiples" in Python
Functional programming in Python Project Euler 2
Project Euler 11 "Maximum product in grid"
Project Euler # 15 "Lattice Path" in Python
Project Euler # 4 "Maximum Palindrome" in Python
Project Euler 9 Retention of calculation results
Project Euler # 3 "Maximum Prime Factors" in Python
Project Euler # 11 "Maximum Product in Grid" in Python
Project Euler # 7 "1000 1st prime number" in Python
Project Euler # 16 "Sum of Powers" in Python
Project Euler # 14 "Longest Collatz Sequence" in Python
I wrote Project Euler 1 in one liner.
Project Euler # 2 "Even Fibonacci Numbers" in Python
Project Euler # 17 "Number of Characters" in Python
Project Euler # 1 "Multiples of 3 and 5" in Python
Project Euler # 8 "Maximum Product in Number String" in Python
Project Euler # 10 "sum of prime numbers" in Python
Project Euler 28 Inefficient Answer Proposal Create "Spiral Numbers"
Project Euler 4 Coding with a new approach fails.
Django Project Baseline
Project Euler # 13 "Sum of Large Numbers" in Python
Project Euler # 6 "Difference in sum of squares" in Python
[Day 2] Project generation