Solution to problem 33
This commit is contained in:
47
src/Python/Problem033.py
Normal file
47
src/Python/Problem033.py
Normal file
@@ -0,0 +1,47 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
"""
|
||||||
|
Created on 04 Mar 2021
|
||||||
|
|
||||||
|
@author: David Doblas Jiménez
|
||||||
|
@email: daviddoji@pm.me
|
||||||
|
|
||||||
|
Solution for problem 33 of Project Euler
|
||||||
|
https://projecteuler.net/problem=33
|
||||||
|
"""
|
||||||
|
|
||||||
|
from utils import timeit
|
||||||
|
|
||||||
|
|
||||||
|
@timeit("Problem 33")
|
||||||
|
|
||||||
|
def compute():
|
||||||
|
"""
|
||||||
|
The fraction 49/98 is a curious fraction, as an inexperienced mathematician
|
||||||
|
in attempting to simplify it may incorrectly believe that 49/98 = 4/8,
|
||||||
|
which is correct, is obtained by cancelling the 9s.
|
||||||
|
|
||||||
|
We shall consider fractions like, 30/50 = 3/5, to be trivial examples.
|
||||||
|
|
||||||
|
There are exactly four non-trivial examples of this type of fraction, less
|
||||||
|
than one in value, and containing two digits in the numerator and denominator.
|
||||||
|
|
||||||
|
If the product of these four fractions is given in its lowest common terms,
|
||||||
|
find the value of the denominator.
|
||||||
|
"""
|
||||||
|
numerator = 1
|
||||||
|
denominator = 1
|
||||||
|
for x in range(10, 100):
|
||||||
|
for y in range(10, 100):
|
||||||
|
if x < y:
|
||||||
|
if str(x)[1] == str(y)[0]:
|
||||||
|
if int(str(y)[1]) != 0:
|
||||||
|
if int(str(x)[0]) / int(str(y)[1]) == x / y:
|
||||||
|
numerator *= x
|
||||||
|
denominator *= y
|
||||||
|
|
||||||
|
return int(denominator/numerator)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
|
||||||
|
print(f"Result for Problem 33: {compute()}")
|
||||||
Reference in New Issue
Block a user