Move Project Euler under puzzles.
This commit is contained in:
21
puzzles/project_euler/p016_PowerDigitSum.py
Normal file
21
puzzles/project_euler/p016_PowerDigitSum.py
Normal file
@@ -0,0 +1,21 @@
|
||||
#Power digit sum
|
||||
#Problem 16
|
||||
#
|
||||
#215 = 32768 and the sum of its digits is 3 + 2 + 7 + 6 + 8 = 26.
|
||||
#
|
||||
#What is the sum of the digits of the number 21000?
|
||||
|
||||
|
||||
pp = 1000
|
||||
|
||||
c = [0 for i in range(0, pp//3+1)]
|
||||
c[0] = 1
|
||||
|
||||
for i in range(0,pp):
|
||||
r = 0
|
||||
for j in range(0,len(c)):
|
||||
p = c[j]*2+r
|
||||
r = p//10
|
||||
c[j] = p%10
|
||||
|
||||
print( sum(c) )
|
||||
Reference in New Issue
Block a user