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.
Any hints on making this faster? My current c++ implementation takes about 4s for N=4, K=2. It's essentially:
(1) brute-forcing every numerator/denominator,
(2) checking the number of common digits to see if we could actually try to cancel at least k,
(3) if so, try all possible ways of cancelling k digits
I can cheat, precompute the 6 possibilities and have a look-up table. But just wondering if there's a mathematical trick to make this problem easier.
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 →
Any hints on making this faster? My current c++ implementation takes about 4s for N=4, K=2. It's essentially: (1) brute-forcing every numerator/denominator, (2) checking the number of common digits to see if we could actually try to cancel at least k, (3) if so, try all possible ways of cancelling k digits
I can cheat, precompute the 6 possibilities and have a look-up table. But just wondering if there's a mathematical trick to make this problem easier.