Bob was handed the following assignment for his programming class. Please note: this is not the actual challenge.
Homework assignment 11: Twin primes
Input: an integer
n ≥ 8, taken from STDIN.
Output: a message to STDOUT, depending on
nis not a prime number, output
nis a prime number, but neither of
n - 2and
n + 2is, output
n + 2are both prime numbers, output
Lower twin prime.
n - 2are both prime numbers, output
Upper twin prime.
Bob tried hard to solve the assignment, but his program kept crashing, and in the end, he gave up and submitted it in hope of partial credit. Nevertheless, Bob's program has the curious property that even though it never does what it's supposed to, the input is still classified correctly depending on the program's behavior: non-primes result in no output, isolated primes in a crash, lower twin primes in an infinite loop with no output, and upper twin primes in an infinite loop that keeps printing the correct message.
Your task is to replicate the behavior or Bob's solution. In other words, write a program that reads a single integer
n ≥ 8 from STDIN or closest equivalent, and does the following:
nis not a prime number, output nothing and exit gracefully.
nis a prime number, but none of
n - 2or
n + 2is, produce a runtime error of some kind. Stack overflows count as runtime errors.
n + 2are both prime numbers, output nothing, but keep running until the program is killed manually (or until you run out of memory).
n - 2are both prime numbers, repeatedly output
Upper twin prime., with or without a trailing newline, to STDOUT or closest equivalent until the program is killed manually (or until you run out of memory).
Incorrect inputs can be ignored.
The idea is that your program should appear correct, but contain hidden bugs that result in the above behavior. Your program should also be short (since programming assignments are graded by hand), but popularity is more important. Thus, your score is number of upvotes - (byte count / 100), higher score being better. Note that your score can be negative.