'''
2**15 = 32768 and the sum of its digits is 3 + 2 + 7 + 6 + 8 = 26.

What is the sum of the digits of the number 2**1000?
'''

from EulerProject_HanFunctions import digits
'''
# check to see whether there is a patern or not.
for i in range(1, 20):
    x=digits(2**i, 10)
    print i, x, sum(x)
# looks random, so let's go for the answer straight
'''
x = 2**1000
y = digits(x, 10)
print 1000, x, sum(y)
Ejemplo n.º 2
0
#Find the sum of the digits in the number 100!




from EulerProject_HanFunctions import factorial
from EulerProject_HanFunctions import digits

#1.I used a brute-force method, and Python worked fine!
for N in range(1, 101):   # 100 inclusive
    X=factorial(N)
    print N, "!=", X, sum(digits(X, 10))

# To save some calculation, I could have excluded any number that is a multiple of 5 (5, 10, 15, 25, ...100).
# However, for 25, exclude 4 as well
# Elif,for a multiple of 5 that is not a multiple of 10, exclude 2 each time.
# I am not sure whether this will reduce the computation drastically or not.

Ejemplo n.º 3
0
# By considering the terms in the Fibonacci sequence whose values do not exceed four million, find the sum of the even-valued terms.

#1. Let's genearate Fibonacci numbers below 4,000,000

from EulerProject_HanFunctions import digits

print digits(1324, 10)

Ejemplo n.º 4
0
#Find the largest palindrome which is a multiple of two 3 digit integers
from EulerProject_HanFunctions import digits

zmax = 0  #initial palindrome
a = 100  # Given 3 digit integer is between a and b
b = 1000
for x in range(a, b):
    for y in range(a, b):
        z = x * y  #a multiple of two 3 digit integers
        # How do we check whether z is a palindrome or not?
        # the minimum z is 10,000, while the maximum is 999,999. So we need to extract the integers with digit 5 or 6
        digit = digits(z,
                       10)  # returns array digit which stores each digit of N

        if (
                z < a * b
        ):  # 5 digit palindrome. Probably does not contain a maximum, since there will be a palindrome with 6 digits
            if (digit[0] == digit[4] and digit[1] == digit[3]):
                if (z > zmax):
                    zmax = z
                    print "5 digit palindrome: ", x, "*", y, "=", z  # z is palindrome
        else:  #6 digit palindrome. The maximum is likely in here
            if (digit[0] == digit[5] and digit[1] == digit[4]
                    and digit[2] == digit[3]):
                if (z > zmax):
                    zmax = z
                    print "6 digit palindrome: ", x, "*", y, "=", z  # z is palindrome
print "maximum palindrome is ", zmax
# Find the sum of all the numbers that can be written as the sum of 5th power of their digits

from EulerProject_HanFunctions import digits

#Find teh maximum such numbers.
maxdigit = 9**5  #9 power 5 is the maximum, which is 5 figure number
digit = 1
while (digit * maxdigit > 10**digit):
    digit = digit + 1
#print digit
maxim = 9**5 * digit  # maximum possible number
summ = 0
print maxim
for candidate in range(2, maxim):
    digitlist = digits(candidate, 10)
    x = 0
    digitsum = 0
    for i in digitlist:
        digitsum = digitsum + i**5
    if digitsum == candidate:
        print digitsum, "is one such a number"
        summ = summ + candidate
print "The sum of all these numbers is", summ
def countingRule2(N):  # For two digit numbers with regular rule
    X = digits(N, 10)
    if X[1] == 1:
        return countingSpecial(X[0]) + 'teen'
    else:  # Special two digits
        return countingSpecial(X[1] * 10) + countingSpecial(X[0])