-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patheuler33.py
56 lines (46 loc) · 1.2 KB
/
euler33.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import sys
def digits(n):
ar=[]
while n:
ar.append(n%10)
n/=10
return ar
def gcd(a,b):
return gcd(b,a%b) if b!=0 else a
def getnewratio(a,b):
if (a[0]==b[0] and a[1]!=b[1]):
d=int(a[1])
e=int(b[1])
if (a[0]==b[1] and a[1]!=b[0]):
d=int(a[1])
e=int(b[0])
if (a[1]==b[0] and a[0]!=b[1]):
d=int(a[0])
e=int(b[1])
if (a[0]!=b[0] and a[1]==b[1]):
d=int(a[0])
e=int(b[0])
return d,e
#print gcd(int(sys.argv[1]),int(sys.argv[2]))
count=0
for i in range(11,100):
for j in range(i+1,100):
a=digits(i)
b=digits(j)
if i%10!=0 and j%10!=0 and(a[0]==b[0] and a[1]!=b[1]) or (a[0]==b[1] and a[1]!=b[0]) or (a[1]==b[0] and a[0]!=b[1]) or (a[0]!=b[0] and a[1]==b[1]):
d,e=getnewratio(a,b)
nde=gcd(d,e)
nij=gcd(i,j)
d=d/nde
e=e/nde
ii=i/nij
jj=j/nij
if ii==d and jj==e:
print i,'/',j
print d,'/',e
count+=1
if count==4:
break
if count==4:
break
print count