@@ -47,86 +47,86 @@ import qualified EulerLib
47
47
- C
48
48
-
49
49
- Basic observations:
50
- - - Except for the degenerate ring 0, each ring k has 6k cells.
50
+ - * Except for the degenerate ring 0, each ring k has 6k cells.
51
51
- The kth ring has exactly 6 corner cells and 6(k - 1) edge cells.
52
- - - In the code we will skip the PD (prime difference) calculation for
52
+ - * In the code we will skip the PD (prime difference) calculation for
53
53
- rings 0 and 1 because the existence of ring 0 breaks many patterns.
54
- - - Doing the PD calculation for rings 0 and 1 by hand (n = 1 to 7
54
+ - * Doing the PD calculation for rings 0 and 1 by hand (n = 1 to 7
55
55
- inclusive), we find that PD(n) = 3 for and only for n = 1, 2.
56
56
-
57
57
- Now let's analyze the characteristics of all cells in rings 2 or above.
58
58
- It's hard to justify these assertions rigorously, but they are true from
59
59
- looking at the spiral diagram.
60
60
-
61
- - - Corner cells along the upward vertical direction and the edge cells
61
+ - * Corner cells along the upward vertical direction and the edge cells
62
62
- immediately to the right of this vertical column are the most interesting,
63
63
- so we will save these cases for last.
64
64
-
65
- - - Claim: Except for cells immediately right of the upward corner column,
65
+ - * Claim: Except for cells immediately right of the upward corner column,
66
66
- no edge cell satisfies PD(n) = 3. Proof: Take an arbitrary edge cell n
67
67
- not immediately to the right of the upward corner column...
68
- - - The two neighbors in the same ring have a difference of 1 compared to n,
68
+ - * The two neighbors in the same ring have a difference of 1 compared to n,
69
69
- which is not a prime number.
70
- - - The two neighbors in the previous (inward) ring are consecutive numbers,
70
+ - * The two neighbors in the previous (inward) ring are consecutive numbers,
71
71
- so exactly one of them has an even absolute difference with n. Because
72
72
- n is in ring 2 or above, the difference with any neighboring number in the
73
73
- previous ring is at least 6. Thus an even number greater than 2 is not prime.
74
- - - Similarly, the two neighbors in the next (outward) ring are consecutive numbers.
74
+ - * Similarly, the two neighbors in the next (outward) ring are consecutive numbers.
75
75
- One of them has an even difference with n, and this number is also at least 6,
76
76
- so one neighbor is definitely not prime.
77
- - - Therefore with at least 4 neighbors that do not have a prime difference, PD(n) <= 2.
77
+ - * Therefore with at least 4 neighbors that do not have a prime difference, PD(n) <= 2.
78
78
- Example of an edge cell n = 11 in ring 2, which is straight left of the origin:
79
79
- 10
80
80
- 24 03
81
81
- 11
82
82
- 25 04
83
83
- 12
84
84
-
85
- - - Claim: No corner cell in the other 5 directions satisfies PD(n) = 3.
85
+ - * Claim: No corner cell in the other 5 directions satisfies PD(n) = 3.
86
86
- Proof: Take an arbitrary corner cell n in the non-upward direction...
87
- - - Two of its neighbors (in the same ring) have a difference of 1,
87
+ - * Two of its neighbors (in the same ring) have a difference of 1,
88
88
- which is not prime.
89
- - - One neighbor is in the previous ring (inward) while three neighbors
89
+ - * One neighbor is in the previous ring (inward) while three neighbors
90
90
- are in the next ring (outward).
91
- - - Let the inner ring neighbor be k and the outer ring's middle neighbor
91
+ - * Let the inner ring neighbor be k and the outer ring's middle neighbor
92
92
- be m. The three outer ring neighbors are {m - 1, m, m + 1}.
93
- - - Then n - k + 6 = m - n. Also, {m - 1, m + 1} have the same parity,
93
+ - * Then n - k + 6 = m - n. Also, {m - 1, m + 1} have the same parity,
94
94
- and {k, m} have the same other parity.
95
- - - Either both {|k - n|, |m - n|} are even or both {|m - 1 - n|, |m + 1 - n|} are even.
95
+ - * Either both {|k - n|, |m - n|} are even or both {|m - 1 - n|, |m + 1 - n|} are even.
96
96
- In any case, all these differences are at least 6, so the even numbers are not prime.
97
- - - Therefore with at least 4 neighbors that do not have a prime difference, PD(n) <= 2.
97
+ - * Therefore with at least 4 neighbors that do not have a prime difference, PD(n) <= 2.
98
98
- Example of a corner cell n = 14 in ring 2, which is straight below the origin:
99
99
- 05
100
100
- 13 15
101
101
- 14
102
102
- 28 30
103
103
- 29
104
104
-
105
- - - Now let's consider an arbitrary upward corner cell n in ring k, with k >= 2.
105
+ - * Now let's consider an arbitrary upward corner cell n in ring k, with k >= 2.
106
106
- We shall give variables to all its neighbors like this:
107
107
- d
108
108
- e f
109
109
- n
110
110
- b c
111
111
- a
112
- - - a is in the previous ring, {b, c} are in the same ring as n,
112
+ - * a is in the previous ring, {b, c} are in the same ring as n,
113
113
- and {d, e, f} are in the next ring.
114
- - - Equations derived from the structure of the hexagonal spiral:
114
+ - * Equations derived from the structure of the hexagonal spiral:
115
115
- n = 3k(k - 1) + 2.
116
116
- a = n - 6(k - 1).
117
117
- b = n + 1.
118
118
- c = n + 6k - 1 = d - 1.
119
119
- d = n + 6k.
120
120
- e = n + 6k + 1 = d + 1.
121
121
- f = n + 6k + 6(k + 1) - 1 = n + 12k + 5.
122
- - - Hence we get these absolute differences with n:
122
+ - * Hence we get these absolute differences with n:
123
123
- |a - n| = 6(k - 1). (Not prime because it's a multiple of 6)
124
124
- |b - n| = 1. (Not prime)
125
125
- |c - n| = 6k - 1. (Possibly prime)
126
126
- |d - n| = 6k. (Not prime because it's a multiple of 6)
127
127
- |e - n| = 6k + 1. (Possibly prime)
128
128
- |f - n| = 12k + 5. (Possibly prime)
129
- - - Therefore for each k >= 2, we need to count how many numbers
129
+ - * Therefore for each k >= 2, we need to count how many numbers
130
130
- in the set {6k - 1, 6k + 1, 12k + 5} are prime.
131
131
- Example of a corner cell n = 8 in ring 2, which is straight above the origin:
132
132
- 20
@@ -135,32 +135,32 @@ import qualified EulerLib
135
135
- 09 19
136
136
- 02
137
137
-
138
- - - Finally let's consider an arbitrary edge cell immediately to the right of the
138
+ - * Finally let's consider an arbitrary edge cell immediately to the right of the
139
139
- upward vertical column. Suppose the cell's value is n and it is in ring k,
140
140
- with k >= 2. Give variables to all its neighbors like this:
141
141
- f
142
142
- c e
143
143
- n
144
144
- a d
145
145
- b
146
- - - {a, b} are in the previous ring, {c, d} are in the current ring, and {e, f} are in
146
+ - * {a, b} are in the previous ring, {c, d} are in the current ring, and {e, f} are in
147
147
- the next ring. The ascending ordering of all these numbers is (a, b, c, d, n, e, f).
148
- - - Equations derived from the structure of the hexagonal spiral:
148
+ - * Equations derived from the structure of the hexagonal spiral:
149
149
- n = 3k(k + 1) + 1.
150
150
- a = n - 6k - 6(k - 1) + 1 = n - 12k + 7.
151
151
- b = n - 6k.
152
152
- c = n - 6k + 1.
153
153
- d = n - 1.
154
154
- e = n + 6(k + 1) - 1 = n + 6k + 5.
155
155
- f = n + 6(k + 1).
156
- - - Hence we get these absolute differences with n:
156
+ - * Hence we get these absolute differences with n:
157
157
- |a - n| = 12k - 7. (Possibly prime)
158
158
- |b - n| = 6k. (Not prime because it's a multiple of 6)
159
159
- |c - n| = 6k - 1. (Possibly prime)
160
160
- |d - n| = 1. (Not prime)
161
161
- |e - n| = 6k + 5. (Possibly prime)
162
162
- |f - n| = 6(k + 1). (Not prime because it's a multiple of 6)
163
- - - Therefore for each k >= 2, we need to count how many numbers
163
+ - * Therefore for each k >= 2, we need to count how many numbers
164
164
- in the set {6k - 1, 6k + 5, 12k - 7} are prime.
165
165
- Example of an edge cell n = 19 in ring 2:
166
166
- 37
0 commit comments