We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Many thanks to JialinOuyang, this helped a lot! Here are some additions:
2a) It is OK for leading zeros to be in both the numerator and the denominator of the "cancelled" fraction. e.g. 3016/6032 = 01/02
3) Trailing zeros are not banned, you just mustn't "cancel" them, so 490/980 = 40/80 is OK, but 490/980 = 4/8 is not.
4) Each fraction should only be counted once, even if it can be validly "cancelled" in more than one way, e.g. 1616/6464 cancels to either 161/644 or 116/464, but it only counts once.
5) Fractions don't have to be completely "cancelled", so 1616/6464 = 161/644 is OK even though there are still 6's in both "cancelled" numbers.
I didn't solve this one until I had tried all of the above both ways - I strongly agree the problem statement should be clearer about the rules.
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Project Euler #33: Digit canceling fractions
You are viewing a single comment's thread. Return to all comments →
Many thanks to JialinOuyang, this helped a lot! Here are some additions:
2a) It is OK for leading zeros to be in both the numerator and the denominator of the "cancelled" fraction. e.g. 3016/6032 = 01/02
3) Trailing zeros are not banned, you just mustn't "cancel" them, so 490/980 = 40/80 is OK, but 490/980 = 4/8 is not.
4) Each fraction should only be counted once, even if it can be validly "cancelled" in more than one way, e.g. 1616/6464 cancels to either 161/644 or 116/464, but it only counts once.
5) Fractions don't have to be completely "cancelled", so 1616/6464 = 161/644 is OK even though there are still 6's in both "cancelled" numbers.
I didn't solve this one until I had tried all of the above both ways - I strongly agree the problem statement should be clearer about the rules.