-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path33.py
More file actions
29 lines (21 loc) · 743 Bytes
/
33.py
File metadata and controls
29 lines (21 loc) · 743 Bytes
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
#!/usr/bin/env python3
# Finds the non-trivial two-digit digit-cancelling fractions.
"""Project Euler Problem 33: https://projecteuler.net/problem=33"""
def solve():
"""Find digit-canceling fractions among two-digit numerators and denominators."""
from fractions import Fraction
two_digit_numbers = [i for i in range(10, 99) if i % 10 != 0]
for i in two_digit_numbers:
if i % 10 == i // 10:
continue
# Create a Fraction object
j = i % 10 * 10 + i // 10
j += 1
while j // 10 == i % 10:
f = Fraction(i, j)
g = Fraction(i // 10, j % 10)
if f == g:
print(i, j)
j += 1
if __name__ == "__main__":
solve()