Happy Primes

HW3 is back to solo – – unlike HW2, you will have no partners for HW3. Remember, only get help from your instructor for HW3, not from anyone else. You can use web resources to help, but then you MUST list any sources you used in your opening comments. “Give credit where credit is due” is an important aspect of professional integrity in software engineering.

Onwards to the HW3 specification. Please read this Wikipedia entry on Happy Numbers: https://en.wikipedia.org/wiki/Happy_number (Links to an external site.). I found it interesting that the origins of happy numbers are unclear. There is even a Dr. Who reference to happy primes:
https://www.youtube.com/watch?v=ee2If8jSxUo (Links to an external site.)

We will be working with 10-happy prime numbers, using the familiar base 10 numbers. For the rest of this specification, when I write “happy prime,” I will mean “10-happy prime.” A happy prime is both a happy number, and prime. Not all happy numbers are prime, and not all primes are happy numbers.

(Strange aside: every single number is happy if you write it in either base 2 or base 4. Can you figure out why?)

Your program will be used to explore the distance between happy primes on the number line. Your program will begin by printing out to the screen a concise explanation of what a 10-happy prime is. The program will continue by asking the interactive user for an integer between 1 and 1,000,000 inclusive. If the user fails to enter a legal integer in the specified range, reprompt until the user succeeds. I will call the legal number entered X. X will form the lower bound of your search for happy primes.

Sample Solution