#!/usr/bin/python

import getopt
import os
import re
import sys


def problem_1():
	total = sum(x for x in range(1000) if x % 3 == 0 or x % 5 == 0)
	print total

def problem_2():
	un2 = 1
	un1 = 2
	un  = un1
	total = 2
	while 1:
		un  = un2 + un1
		if un >= 4000000:
			break
		if un % 2 == 0:
			total += un
		un2 = un1
		un1 = un
	print total

def usage():
	basename = os.path.basename(sys.argv[0]);
	print '''
usage: %s [option] filename
Options:
	-p --problem Print of solution of problem p
''' % basename

def main():
	try:
		opts, argv = getopt.getopt(sys.argv[1:],
				"hp:",
				["help", "problem="])
	except getopt.GetoptError, err:
		# print help information and exit:
		print str(err) # will print something like "option -a not recognized"
		usage()
		sys.exit(2)
	problem = 0
	for o, a in opts:
		if o in ("-h", "--help"):
			usage()
			sys.exit()
		elif o in ("-p", "--problem"):
			problem = int(a)
		else:
			assert False, "unhandled option"

	if problem == 0:
		usage()
		sys.exit(2)
	if problem == 1:
		problem_1()
	elif problem == 2:
		problem_2()
	else:
		print 'Unkown problem: %d' % problem

if __name__ == "__main__":
	main()

@@ -59,16 +59,62 @@
 t sys%0A%0A%0A
+%22%22%22%0A%09Hard to be more condensed than that.%0A%22%22%22%0A
 def prob
@@ -381,24 +381,630 @@
 rint total%0A%0A
+def problem_3():%0A%09n = 600851475143;%0A%09p = 2%0A%09while n %3E 1:%0A%09%09if n %25 p == 0:%0A%09%09%09n = n / p%0A%09%09else:%0A%09%09%09p += 1%0A%09print p%0A%0A%22%22%22%0A%09Could check for less numbers.%0A%0A%09p = abccba%0A%09...%0A%09p = 11(9091a + 910b + 100c)%0A%0A%09Also I don't need to store the palindromes in an%0A%09array but I find it fun.%0A%22%22%22%0Adef problem_4():%0A%09palindromes = %5B%5D%0A%09for i in range(100, 1000):%0A%09%09for j in range(100, 1000):%0A%09%09%09p = i * j%0A%09%09%09s = str(p)%0A%09%09%09palindrome = True%0A%09%09%09k = 0%0A%09%09%09l = len(s)%0A%09%09%09while k %3C= l / 2:%0A%09%09%09%09if s%5Bk%5D != s%5Bl - 1 - k%5D:%0A%09%09%09%09%09palindrome = False%0A%09%09%09%09%09break%0A%09%09%09%09k += 1%0A%09%09%09if palindrome:%0A%09%09%09%09palindromes.append(p)%0A%09print max(palindromes)%0A%0A
 def usage():
@@ -1697,16 +1697,16 @@
 m == 2:%0A
-
 %09%09proble
@@ -1711,16 +1711,84 @@
 lem_2()%0A
+%09elif problem == 3:%0A%09%09problem_3()%0A%09elif problem == 4:%0A%09%09problem_4()%0A
 %09else:%0A%09

found solution of problem 3 and 4