Here is a fairly simple programming challenge; an opportunity for some of the young talent to show their skills.
Respect will be awarded to the programmer who writes the most time efficient solution (multithreading welcome), the most interesting solution (recursion welcome), and the most elegant solution.
For the first 9 prime numbers (excluding 2),
3, 5, 7, 11, 13, 17, 19, 23, 29
3 + 7 = 10
5 + 11 = 16
7 + 13 = 20
11 + 17 = 28
13 + 19 = 32
17 + 23 = 40
19 + 29 = 48
10 + 20 = 30
16 + 28 = 44
20 + 32 = 52
28 + 40 = 68
32 + 48 = 80
44 - 30 =
14
52 - 44 =
8
68 - 52 =
16
80 - 68 =
12
The sequence: 14, 8, 16, 12 (for primes 3 through 29)
Your program should output the described sequence for primes from 3 to n.
After the sequence has been printed, print the maximum value in the sequence,
the minimum value in the sequence, the most commonly occurring value in the sequence (mode) (multiple if there is a tie), and the largest integer gap between consecutive terms in the sequence.
example output:
primes 3 to 29
(14, 8, 16, 12)
Max: 16
Min: 8
Mode: 14, 8, 16, 12
Largest Gap: 8 |