Problem 33

completed December 9, 2011

Comments

I used a little critical thinking to deduce that the fraction must be of the form ab/bc = a/c where a does not equal c. After this, it was pretty easy to find the four fractions necessary.

Code

#take a string of form (1, 2, a, b) and make it into one word or number of form 12ab
def str2num(n):
	return ''.join(map(str, n))		
	

# find: ab / bc = a / c

myset = []
for a in range(1, 10):
	for b in range(1, 10):
		for c in range(1, 10):
			ab = float(str2num((a, b)))
			bc = float(str2num((b, c)))
			if ((ab / bc) == (float(a) / float(c))) and (ab != bc):
				print ab, '/', bc
				myset.append([a, c])
			
print myset