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.
Took me some time to realise the output of 5 1 2 is 10007 10009 instead of 10007 10037 (Python, it gave wrong answer for Test #3 and #10).
Was trying to save time by returning the first plausible result from digit replacement generated by looping through digits from 0 to 9, and it turns out that way it's not necessarily the minimum result.
Eventually I computed all plausible results from all digit replacement and its corresponding permutations. I would say it's too ugly to my taste.
EDIT: Made use of generator combining permutations with deque() to yield the next smallest replacement position, so it does not have to generate the whole thing in advance. Sounds simple, troublesome to implement. The slowest time for me is 4.74s for #18. Previous version took almost 8s...
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Project Euler #51: Prime digit replacements
You are viewing a single comment's thread. Return to all comments →
Took me some time to realise the output of
5 1 2
is10007 10009
instead of10007 10037
(Python, it gave wrong answer for Test #3 and #10).Was trying to save time by returning the first plausible result from digit replacement generated by looping through digits from
0
to9
, and it turns out that way it's not necessarily the minimum result.Eventually I computed all plausible results from all digit replacement and its corresponding permutations. I would say it's too ugly to my taste.
EDIT: Made use of generator combining permutations with
deque()
toyield
the next smallest replacement position, so it does not have to generate the whole thing in advance. Sounds simple, troublesome to implement. The slowest time for me is 4.74s for #18. Previous version took almost 8s...