Palindromic Primes
About This Kata
This kata is about refactoring for performance. It is worth noting that there are two approaches at from the outset. While transitioning between them is possible, you may want to commit to one or the other before you get started. These different approaches will exercise different types of optimization strategies.
- Simple: A single-threaded generator.
- Complex: A producer/consumer model.
Problem Description
This kata is about generating palindromic prime numbers.
- A prime number is a number for which the integer divisors are only itself and one. EG: 2, 3, 5, 7, 11, 13, 17 etc.
- A palindrome is something that reads the same forward and backward. Classic examples include words like “Radar”
- A palindromic prime, therefore, is a prime number that reads the same forward and backward. 191 and 313 are palindromic primes.
Objective
- Your goal is to output the largest number of CONSECUTIVE palindromic primes you can in some time interval (I recommend 1 minute to get started).
- Caching primes from the last time you ran the program is cheating.
- The optimizations that pay dividends will be partially driven by the interval you choose so you may wish to play with different optimization strategies as you work.
A word of caution
- It is technically possible to complete this kata by instantiating cloud infrastructure to run the program massively in parallel. It’s not my money, but you should really make sure you have billing limits enabled with your cloud provider before you do this.