Thursday Code Puzzler: Finding Twin Primes
Join the DZone community and get the full member experience.
Join For FreeTime for our weekly code puzzle. The idea is simple: solve the coding problem as efficiently as you can, in any language or framework that you think is suitable. Today problem is to find all the twin primes within a certain range. A twin prime is a pair of prime numbers that differs by two. Two examples would be (3,5) and (5,7).
What you have to do is write a method/function that takes an integer input (let's call it limit) and finds all the twin primes up to that limit.
As you are free to use any language, it will be interesting to see which approach will give the most readable code.
Note: Even though there really is nothing stopping you from finding a solution to this on the internet, try to keep honest, and come up with your own answer. It's all about the participation!
Thanks to everyone who participated in the last few code puzzlers.
Opinions expressed by DZone contributors are their own.
Comments