Example #1
0
#!/usr/bin/env python
# http://projecteuler.net/index.php?section=problems&id=16
from EulerLibs import StrLibs
answer = StrLibs.sumDigits(str(2**1000))
print answer
Example #2
0
#!/usr/bin/env python
# http://projecteuler.net/index.php?section=problems&id=4
import math
from EulerLibs import StrLibs

	
i = 999 * 999
answer = 0
while True:
	if StrLibs.isPalindrome(str(i)):
		# check and see if it is the product of two three-digit numbers
		j = 999
		while j >= 100:
			if (not i % j) and (i / j <= 999) and (i / j >= 100):
				# print "%d times %d equals %d" % (j, i / j, i)
				answer = i
				break
			j -= 1
		
		if answer > 0:
			break
			
	i -= 1
	
print answer
Example #3
0
#!/usr/bin/env python
# http://projecteuler.net/index.php?section=problems&id=22
import csv
from EulerLibs import StrLibs

class customDialect(csv.Dialect):
	delimiter = ','
	doublequote = False
	escapechar = '\\'
	lineterminator = "\n"
	quotechar = '"'
	quoting = False
	skipinitialspace = False

names_by_line = csv.reader(file('data/names.txt', 'r'), dialect = customDialect)
names = list(names_by_line)[0]
names.sort()

answer = 0
cursor = 0
while cursor < len(names):	
	value = StrLibs.wordValue(names[cursor])
	cursor += 1
	answer += (cursor * value)
			
print answer
Example #4
0
#!/usr/bin/env python
# http://projecteuler.net/index.php?section=problems&id=20
import math
from EulerLibs import MathLibs,StrLibs

f100 = str(MathLibs.factorial(100))
answer = StrLibs.sumDigits(f100)
print answer