Skip to content

Instantly share code, notes, and snippets.

@jakedobkin
Created December 5, 2011 00:34
Show Gist options
  • Select an option

  • Save jakedobkin/1431792 to your computer and use it in GitHub Desktop.

Select an option

Save jakedobkin/1431792 to your computer and use it in GitHub Desktop.
Euler 33
# first we'll need a set to store results in- that means we won't need to de-dupe
h=set()
total=0;
# now, we'lll make the fractions 10 to 99 in numerator and denominator
for a in range(10,100):
for b in range(10,100):
if (a!=b):
numerator = str(a)
denominator = str(b)
n1 = numerator[0:1]
n2 = numerator[1:2]
d1 = denominator[0:1]
d2 = denominator[1:2]
big_fraction = (a*1.0)/b*1.0
if (n1 == d1 and d2!="0"):
small_fraction = (int(n2)*1.0)/(int(d2)*1.0)
if big_fraction == small_fraction:
h.add(str(a)+"/"+str(b))
if (n1 == d2 and d2!="0"):
small_fraction = (int(n2)*1.0)/(int(d1)*1.0)
if big_fraction == small_fraction:
h.add(str(a)+"/"+str(b))
if (n2 == d1 and d2!="0"):
small_fraction = (int(n1)*1.0)/(int(d2)*1.0)
if big_fraction == small_fraction:
h.add(str(a)+"/"+str(b))
if (n2 == d2 and d2!="0"):
small_fraction = (int(n1)*1.0)/(int(d1)*1.0)
if big_fraction == small_fraction:
h.add(str(a)+"/"+str(b))
print h
# then you need to multiply just one version of each- i did it by hand
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment