2 ms·
I'm curious how you got it to even go that fast. My best solution takes about 6 milliseconds, so 20x longer.
by piinbinary 9y ago
I'm curious how you got it to even go that fast. My best solution takes about 6 milliseconds, so 20x longer.
- dhbradshaw 9y agoI used a branch and prune algorithm, starting with the 1 digit primes and then adding digits to the right, pruning using a non-memoising prime test and testing for left truncatability to see if the new numbers should be added to the sum. The tree came to an end fairly quickly, which made the algorithm fast. I also avoided any string manipulation, favoring truncating by using integer division for right truncation and modulus for left truncation. Is that similar to your algorithm?
- piinbinary 9y agoAh, I guessed that you might be taking some approach that generated numbers to try. Mine was the brute-force "calculate all primes under a million then test them all" approach.