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.
// define function to check if two numbers has the cancelling behaviour let isCancelling a b = let aStr, bStr = a.ToString(), b.ToString() if aStr. = bStr. then double(aStr..ToString())/double(bStr..ToString()) = double(a)/double(b) else if aStr. = bStr. then double(aStr..ToString())/double(bStr..ToString()) = double(a)/double(b) else if aStr. = bStr. then double(aStr..ToString())/double(bStr..ToString()) = double(a)/double(b) else if aStr. = bStr. then double(aStr..ToString())/double(bStr..ToString()) = double(a)/double(b) else false // define function to find the greatest common dividor let gcd a b = [2..min a b] |> List.rev |> Seq.filter (fun x -> a % x = 0 && b % x = 0) |> Seq.head // define function that returns numbers >= n which are not multiples of 10 // and have two distinct digits (i.e. 11, 22 only have one distinct digits) let numbers n = [n..99] |> List.filter (fun x -> x % 10 <> 0 && (x % 10 <> x/10)) let answer = // first work out the product of all 4 fractions, in fractions form (num, denom) let fraction = numbers 10 |> List.collect (fun x -> numbers (x+1) |> List.map (fun y -> (x, y))) |> List.filter (fun (x, y) -> isCancelling x y) |> List.reduce (fun (num, denom) (x, y) -> (num*x, denom*y)) // then define the denominator by the greatest common divisor (snd fraction) / gcd (fst fraction) (snd fraction)
Enjoy what you’re reading? Subscribe to my newsletter and get more content on AWS and serverless technologies delivered straight to your inbox.
I’m an AWS Serverless Hero and the author of Production-Ready Serverless. I have run production workload at scale in AWS for nearly 10 years and I have been an architect or principal engineer with a variety of industries ranging from banking, e-commerce, sports streaming to mobile gaming. I currently work as an independent consultant focused on AWS and serverless.
In this course, we’ll cover everything you need to know to use AWS Step Functions service effectively. Including basic concepts, HTTP and event triggers, activities, design patterns and best practices.
Here is a complete list of all my posts on serverless and AWS Lambda. In the meantime, here are a few of my most popular blog posts.
- Lambda optimization tip – enable HTTP keep-alive
- You are thinking about serverless costs all wrong
- Many faced threats to Serverless security
- We can do better than percentile latencies
- I’m afraid you’re thinking about AWS Lambda cold starts all wrong
- Yubl’s road to Serverless
- AWS Lambda – should you have few monolithic functions or many single-purposed functions?
- AWS Lambda – compare coldstart time with different languages, memory and code sizes
- Guys, we’re doing pagination wrong