Skip to content

Commit 5a659fe

Browse files
committed
P71, P145: Tweaked bullet points in Python solution comments for consistency..
P128: Tweaked bullet points in Haskell solution comments for consistency.
1 parent 3635e91 commit 5a659fe

File tree

3 files changed

+34
-34
lines changed

3 files changed

+34
-34
lines changed

haskell/p128.hs

+26-26
Original file line numberDiff line numberDiff line change
@@ -47,86 +47,86 @@ import qualified EulerLib
4747
- C
4848
-
4949
- 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.
5151
- 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
5353
- 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
5555
- inclusive), we find that PD(n) = 3 for and only for n = 1, 2.
5656
-
5757
- Now let's analyze the characteristics of all cells in rings 2 or above.
5858
- It's hard to justify these assertions rigorously, but they are true from
5959
- looking at the spiral diagram.
6060
-
61-
- - Corner cells along the upward vertical direction and the edge cells
61+
- * Corner cells along the upward vertical direction and the edge cells
6262
- immediately to the right of this vertical column are the most interesting,
6363
- so we will save these cases for last.
6464
-
65-
- - Claim: Except for cells immediately right of the upward corner column,
65+
- * Claim: Except for cells immediately right of the upward corner column,
6666
- no edge cell satisfies PD(n) = 3. Proof: Take an arbitrary edge cell n
6767
- 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,
6969
- 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,
7171
- so exactly one of them has an even absolute difference with n. Because
7272
- n is in ring 2 or above, the difference with any neighboring number in the
7373
- 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.
7575
- One of them has an even difference with n, and this number is also at least 6,
7676
- 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.
7878
- Example of an edge cell n = 11 in ring 2, which is straight left of the origin:
7979
- 10
8080
- 24 03
8181
- 11
8282
- 25 04
8383
- 12
8484
-
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.
8686
- 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,
8888
- 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
9090
- 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
9292
- 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,
9494
- 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.
9696
- 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.
9898
- Example of a corner cell n = 14 in ring 2, which is straight below the origin:
9999
- 05
100100
- 13 15
101101
- 14
102102
- 28 30
103103
- 29
104104
-
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.
106106
- We shall give variables to all its neighbors like this:
107107
- d
108108
- e f
109109
- n
110110
- b c
111111
- 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,
113113
- 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:
115115
- n = 3k(k - 1) + 2.
116116
- a = n - 6(k - 1).
117117
- b = n + 1.
118118
- c = n + 6k - 1 = d - 1.
119119
- d = n + 6k.
120120
- e = n + 6k + 1 = d + 1.
121121
- 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:
123123
- |a - n| = 6(k - 1). (Not prime because it's a multiple of 6)
124124
- |b - n| = 1. (Not prime)
125125
- |c - n| = 6k - 1. (Possibly prime)
126126
- |d - n| = 6k. (Not prime because it's a multiple of 6)
127127
- |e - n| = 6k + 1. (Possibly prime)
128128
- |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
130130
- in the set {6k - 1, 6k + 1, 12k + 5} are prime.
131131
- Example of a corner cell n = 8 in ring 2, which is straight above the origin:
132132
- 20
@@ -135,32 +135,32 @@ import qualified EulerLib
135135
- 09 19
136136
- 02
137137
-
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
139139
- upward vertical column. Suppose the cell's value is n and it is in ring k,
140140
- with k >= 2. Give variables to all its neighbors like this:
141141
- f
142142
- c e
143143
- n
144144
- a d
145145
- 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
147147
- 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:
149149
- n = 3k(k + 1) + 1.
150150
- a = n - 6k - 6(k - 1) + 1 = n - 12k + 7.
151151
- b = n - 6k.
152152
- c = n - 6k + 1.
153153
- d = n - 1.
154154
- e = n + 6(k + 1) - 1 = n + 6k + 5.
155155
- f = n + 6(k + 1).
156-
- - Hence we get these absolute differences with n:
156+
- * Hence we get these absolute differences with n:
157157
- |a - n| = 12k - 7. (Possibly prime)
158158
- |b - n| = 6k. (Not prime because it's a multiple of 6)
159159
- |c - n| = 6k - 1. (Possibly prime)
160160
- |d - n| = 1. (Not prime)
161161
- |e - n| = 6k + 5. (Possibly prime)
162162
- |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
164164
- in the set {6k - 1, 6k + 5, 12k - 7} are prime.
165165
- Example of an edge cell n = 19 in ring 2:
166166
- 37

python/p071.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@
1414
# We consider each (integer) denominator d from 1 to 1000000 by brute force.
1515
# For a given d, what is the largest integer n such that n/d < 3/7?
1616
#
17-
# * If d is a multiple of 7, then the integer n' = (d / 7) * 3 satisfies n'/d = 3/7.
17+
# - If d is a multiple of 7, then the integer n' = (d / 7) * 3 satisfies n'/d = 3/7.
1818
# Hence we choose n = n' - 1 = (d / 7) * 3 - 1, so that n/d < 3/7.
1919
# Since (d / 7) * 3 is already an integer, it is equal to floor(d * 3 / 7),
2020
# which will unifie with the next case. Thus n = floor(d * 3 / 7) - 1.
21-
# * Otherwise d is not a multiple of 7, so choosing n = floor(d * 3 / 7)
21+
# - Otherwise d is not a multiple of 7, so choosing n = floor(d * 3 / 7)
2222
# will automatically satisfy n/d < 3/7, and be the largest possible n
2323
# due to the definition of the floor function.
2424
#

python/p145.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@
1515
# reversed number does not have leading zeros.
1616
#
1717
# Consider different cases for the number of digits n (from 1 to 9, but the arguments apply generally):
18-
# * n = 1:
18+
# - n = 1:
1919
# Clearly there are no solutions because the last digit is always even.
2020
#
21-
# * n = 0 mod 2:
21+
# - n = 0 mod 2:
2222
# We begin by proving that when a number is "reversible", the process of adding
2323
# the number to the reverse of itself will involve no carries in the arithmetic.
2424
# Normally a rigorous proof would require the use of mathematical induction,
@@ -70,7 +70,7 @@
7070
# (9,0).
7171
# Therefore by combinatorics, there are 20 * 30^(n/2 - 1) reversible n-digit numbers when n is even.
7272
#
73-
# * n = 1 mod 2:
73+
# - n = 1 mod 2:
7474
# Let's illustrate what happens with a 7-digit number abcdefg:
7575
# 0101010
7676
# abcdefg
@@ -93,7 +93,7 @@
9393
# This is why we get the alternating pattern of carries in the adding process.
9494
#
9595
# The rest of the work is to enumerate the possibilities for each type of digit(s) in the number:
96-
# * Pairs of digits which take no carry and must generate a carry (20 choices):
96+
# - Pairs of digits which take no carry and must generate a carry (20 choices):
9797
# (9,8), (9,6), (9,4), (9,2),
9898
# (8,9), (8,7), (8,5), (8,3),
9999
# (7,8), (7,6), (7,4),
@@ -103,7 +103,7 @@
103103
# (3,8),
104104
# (2,9).
105105
# Note that the first and last digits fall into this category, and there are no 0s at all.
106-
# * Non-middle pairs of digits which take a carry and generate no carry (25 choices):
106+
# - Non-middle pairs of digits which take a carry and generate no carry (25 choices):
107107
# (0,0), (0,2), (0,4), (0,6), (0,8),
108108
# (1,1), (1,3), (1,5), (1,7),
109109
# (2,0), (2,2), (2,4), (2,6),
@@ -113,7 +113,7 @@
113113
# (6,0), (6,2),
114114
# (7,1),
115115
# (8,0).
116-
# * Middle single digit, which takes a carry and generates no carry (5 choices): 0, 1, 2, 3, 4.
116+
# - Middle single digit, which takes a carry and generates no carry (5 choices): 0, 1, 2, 3, 4.
117117
# All in all, there are 5 * 20^((n + 1)/4) * 25^((n - 3)/4) = 100 * 500^((n - 3)/4)
118118
# reversible n-digit numbers when n = 3 mod 4.
119119
def compute():

0 commit comments

Comments
 (0)