From 110d4faf401ba2e566586bb3d3281a9a654a27a8 Mon Sep 17 00:00:00 2001 From: Philippe Zwietering Date: Mon, 22 Feb 2021 20:51:32 +0100 Subject: [PATCH] Manually edit end result to simplified fraction --- 33/main.py | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 33/main.py diff --git a/33/main.py b/33/main.py new file mode 100644 index 0000000..30e61fa --- /dev/null +++ b/33/main.py @@ -0,0 +1,53 @@ +''' +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. +''' + +def listify(i): + return [int(x) for x in str(i)] + +def check(num, denom): + result = False + + frac = num / denom + + lnum = listify(num) + ldenom = listify(denom) + + if lnum[0] == ldenom[0] and ldenom[1] != 0: + result = lnum[1] / ldenom[1] == frac + elif lnum[1] == ldenom[0] and ldenom[1] != 0: + result = lnum[0] / ldenom[1] == frac + elif lnum[0] == ldenom[1]: + result = lnum[1] / ldenom[0] == frac + elif lnum[1] == ldenom[1]: + result = lnum[0] / ldenom[0] == frac + + return result + +def main(): + print("Hello, this is Patrick") + + numres = 1 + denomres = 1 + + for denom in range(11, 100): + for num in range(10, denom): + if not (denom % 10 == 0 and num % 10 == 0) and check(num, denom): + numres *= num + denomres *= denom + + print(num, denom) + + print(f"{numres}/{denomres}") + + + + +if __name__ == "__main__": + main() \ No newline at end of file