Project Euler 73 - Counting fractions in a range
Project Euler 73 - Counting fractions in a range
Official link: https://projecteuler.net/problem=73
Thought Process
Thought Process
Nothing very smart here, I do a double nested loop for variables n and d, where n goes from 1 to 12000 and d goes from 12000 to n backwards, If 1/3 < n/d < 1/2 I store it in a list, then I take the length of the set to remove duplicates.
Don't really have to worry about precision errors because 12,000 is such a small number, code takes ~8 seconds
Edit: For some reason the emulator I use below was having troubles so I made a second algorithm which uses gcd(n,d) to eliminate duplicates instead of making the list a set, it's a bit slower ~15 seconds
Interactive Code
Interactive Code
Please input an integer (yourinput)
Code will output the number of fractions between 1/3 and 1/2 where d = yourinput