Exemplo n.º 1
0
Arquivo: 034.py Projeto: zmj/Euler
def isSumOfDigitFactorial(n):
	sum = 0
	for digitChr in str(n):
		digit = int(digitChr)
		sum += factorial(digit)
		if sum > n:
			return False
	return sum == n
Exemplo n.º 2
0
Arquivo: 043.py Projeto: zmj/Euler
from zMath import nthLexiPerm
from zMath import factorial

def hasWeirdProperty(n): #10 digit number
	s = str(n)
	if s[0] == '0':
		return False

	return int(s[1:4]) % 2 == 0 and int(s[2:5]) % 3 == 0 and int(s[3:6]) % 5 == 0 and int(s[4:7]) % 7 == 0 and int(s[5:8]) % 11 == 0 and int(s[6:9]) % 13 == 0 and int(s[7:10]) % 17 == 0


sum = 0
sequence = range(0, 10)
#should probably write a permutation generator instead of using this function
for permutationIndex in range(0, factorial(10)):
	permutation = nthLexiPerm(sequence, permutationIndex)
	if hasWeirdProperty(permutation):
		sum += int(permutation)

print sum
Exemplo n.º 3
0
Arquivo: 041.py Projeto: zmj/Euler
from zMath import nthLexiPerm
from zMath import isPrimeSimple
from zMath import factorial
import sys

for numDigits in range(9, 0, -1):
	sequence = range(1, numDigits+1)
	sequence.reverse()
	#should probably write a function to generate all permutations
	for permutationIndex in range(0, factorial(numDigits)):
		permutationStr = nthLexiPerm(sequence, permutationIndex)
		#print str(permutationIndex) + ": "+str(permutationStr)
		permutation = int(permutationStr)
		if isPrimeSimple(permutation):
			print permutation
			sys.exit(0)
Exemplo n.º 4
0
Arquivo: 015.py Projeto: zmj/Euler
from zMath import factorial

print (factorial(40) / (factorial(20) * factorial(20)))
Exemplo n.º 5
0
Arquivo: 034.py Projeto: zmj/Euler
from zMath import factorial

maxExp = 1
while True:
	if factorial(9)*maxExp < 10**maxExp:
		break
	else:
		maxExp += 1


def isSumOfDigitFactorial(n):
	sum = 0
	for digitChr in str(n):
		digit = int(digitChr)
		sum += factorial(digit)
		if sum > n:
			return False
	return sum == n

sum = 0
for i in range(10, 10**(maxExp-1)):
	if isSumOfDigitFactorial(i):
		sum += i

print sum
Exemplo n.º 6
0
Arquivo: 020.py Projeto: zmj/Euler
from zMath import factorial

numStr = str(factorial(100))
sum = 0
for c in numStr:
    sum += int(c)
print sum