Problem 99

completed January 12, 2012

Try One

Comments

The numbers here are just way to big to work with. Also, it’s really inefficient to use the power function with these large numbers.

Code

def power(b, e):
	answer = 1
	for i in range(e):
		answer = answer * b
	return answer

n = 1

number = [0, 0]
for p in pairs[:5]:
	print p, n
	big = power(p[0], p[1])
	if big > number[0]:
		number = [big, n]
	n += 1

print number[1]

Try Two

Comments

It finally dawned on me to use logorithms to solve this one. It made the numbers smaller and easier to deal with. With that change, the problem was solvable in under 1 second.

Code

big = [0, 0]
for i in range(len(p)):
	this = [p[i][1]*log(p[i][0]), i+1]
	if this[0] > big[0]:
		big = this

print big