From 5a659fe3b7a6575b3de72933a8f031ac6d720a08 Mon Sep 17 00:00:00 2001
From: Project Nayuki
Date: Sat, 10 Mar 2018 06:58:31 +0000
Subject: [PATCH] P71, P145: Tweaked bullet points in Python solution comments
for consistency.. P128: Tweaked bullet points in Haskell solution comments
for consistency.

haskell/p128.hs  52 ++++++++++++++++++++++++
python/p071.py  4 ++
python/p145.py  12 ++++++
3 files changed, 34 insertions(+), 34 deletions()
diff git a/haskell/p128.hs b/haskell/p128.hs
index e4871d9..7173dd1 100644
 a/haskell/p128.hs
+++ b/haskell/p128.hs
@@ 47,34 +47,34 @@ import qualified EulerLib
 C

 Basic observations:
   Except for the degenerate ring 0, each ring k has 6k cells.
+  * Except for the degenerate ring 0, each ring k has 6k cells.
 The kth ring has exactly 6 corner cells and 6(k  1) edge cells.
   In the code we will skip the PD (prime difference) calculation for
+  * In the code we will skip the PD (prime difference) calculation for
 rings 0 and 1 because the existence of ring 0 breaks many patterns.
   Doing the PD calculation for rings 0 and 1 by hand (n = 1 to 7
+  * Doing the PD calculation for rings 0 and 1 by hand (n = 1 to 7
 inclusive), we find that PD(n) = 3 for and only for n = 1, 2.

 Now let's analyze the characteristics of all cells in rings 2 or above.
 It's hard to justify these assertions rigorously, but they are true from
 looking at the spiral diagram.

   Corner cells along the upward vertical direction and the edge cells
+  * Corner cells along the upward vertical direction and the edge cells
 immediately to the right of this vertical column are the most interesting,
 so we will save these cases for last.

   Claim: Except for cells immediately right of the upward corner column,
+  * Claim: Except for cells immediately right of the upward corner column,
 no edge cell satisfies PD(n) = 3. Proof: Take an arbitrary edge cell n
 not immediately to the right of the upward corner column...
   The two neighbors in the same ring have a difference of 1 compared to n,
+  * The two neighbors in the same ring have a difference of 1 compared to n,
 which is not a prime number.
   The two neighbors in the previous (inward) ring are consecutive numbers,
+  * The two neighbors in the previous (inward) ring are consecutive numbers,
 so exactly one of them has an even absolute difference with n. Because
 n is in ring 2 or above, the difference with any neighboring number in the
 previous ring is at least 6. Thus an even number greater than 2 is not prime.
   Similarly, the two neighbors in the next (outward) ring are consecutive numbers.
+  * Similarly, the two neighbors in the next (outward) ring are consecutive numbers.
 One of them has an even difference with n, and this number is also at least 6,
 so one neighbor is definitely not prime.
   Therefore with at least 4 neighbors that do not have a prime difference, PD(n) <= 2.
+  * Therefore with at least 4 neighbors that do not have a prime difference, PD(n) <= 2.
 Example of an edge cell n = 11 in ring 2, which is straight left of the origin:
 10
 24 03
@@ 82,19 +82,19 @@ import qualified EulerLib
 25 04
 12

   Claim: No corner cell in the other 5 directions satisfies PD(n) = 3.
+  * Claim: No corner cell in the other 5 directions satisfies PD(n) = 3.
 Proof: Take an arbitrary corner cell n in the nonupward direction...
   Two of its neighbors (in the same ring) have a difference of 1,
+  * Two of its neighbors (in the same ring) have a difference of 1,
 which is not prime.
   One neighbor is in the previous ring (inward) while three neighbors
+  * One neighbor is in the previous ring (inward) while three neighbors
 are in the next ring (outward).
   Let the inner ring neighbor be k and the outer ring's middle neighbor
+  * Let the inner ring neighbor be k and the outer ring's middle neighbor
 be m. The three outer ring neighbors are {m  1, m, m + 1}.
   Then n  k + 6 = m  n. Also, {m  1, m + 1} have the same parity,
+  * Then n  k + 6 = m  n. Also, {m  1, m + 1} have the same parity,
 and {k, m} have the same other parity.
   Either both {k  n, m  n} are even or both {m  1  n, m + 1  n} are even.
+  * Either both {k  n, m  n} are even or both {m  1  n, m + 1  n} are even.
 In any case, all these differences are at least 6, so the even numbers are not prime.
   Therefore with at least 4 neighbors that do not have a prime difference, PD(n) <= 2.
+  * Therefore with at least 4 neighbors that do not have a prime difference, PD(n) <= 2.
 Example of a corner cell n = 14 in ring 2, which is straight below the origin:
 05
 13 15
@@ 102,16 +102,16 @@ import qualified EulerLib
 28 30
 29

   Now let's consider an arbitrary upward corner cell n in ring k, with k >= 2.
+  * Now let's consider an arbitrary upward corner cell n in ring k, with k >= 2.
 We shall give variables to all its neighbors like this:
 d
 e f
 n
 b c
 a
   a is in the previous ring, {b, c} are in the same ring as n,
+  * a is in the previous ring, {b, c} are in the same ring as n,
 and {d, e, f} are in the next ring.
   Equations derived from the structure of the hexagonal spiral:
+  * Equations derived from the structure of the hexagonal spiral:
 n = 3k(k  1) + 2.
 a = n  6(k  1).
 b = n + 1.
@@ 119,14 +119,14 @@ import qualified EulerLib
 d = n + 6k.
 e = n + 6k + 1 = d + 1.
 f = n + 6k + 6(k + 1)  1 = n + 12k + 5.
   Hence we get these absolute differences with n:
+  * Hence we get these absolute differences with n:
 a  n = 6(k  1). (Not prime because it's a multiple of 6)
 b  n = 1. (Not prime)
 c  n = 6k  1. (Possibly prime)
 d  n = 6k. (Not prime because it's a multiple of 6)
 e  n = 6k + 1. (Possibly prime)
 f  n = 12k + 5. (Possibly prime)
   Therefore for each k >= 2, we need to count how many numbers
+  * Therefore for each k >= 2, we need to count how many numbers
 in the set {6k  1, 6k + 1, 12k + 5} are prime.
 Example of a corner cell n = 8 in ring 2, which is straight above the origin:
 20
@@ 135,7 +135,7 @@ import qualified EulerLib
 09 19
 02

   Finally let's consider an arbitrary edge cell immediately to the right of the
+  * Finally let's consider an arbitrary edge cell immediately to the right of the
 upward vertical column. Suppose the cell's value is n and it is in ring k,
 with k >= 2. Give variables to all its neighbors like this:
 f
@@ 143,9 +143,9 @@ import qualified EulerLib
 n
 a d
 b
   {a, b} are in the previous ring, {c, d} are in the current ring, and {e, f} are in
+  * {a, b} are in the previous ring, {c, d} are in the current ring, and {e, f} are in
 the next ring. The ascending ordering of all these numbers is (a, b, c, d, n, e, f).
   Equations derived from the structure of the hexagonal spiral:
+  * Equations derived from the structure of the hexagonal spiral:
 n = 3k(k + 1) + 1.
 a = n  6k  6(k  1) + 1 = n  12k + 7.
 b = n  6k.
@@ 153,14 +153,14 @@ import qualified EulerLib
 d = n  1.
 e = n + 6(k + 1)  1 = n + 6k + 5.
 f = n + 6(k + 1).
   Hence we get these absolute differences with n:
+  * Hence we get these absolute differences with n:
 a  n = 12k  7. (Possibly prime)
 b  n = 6k. (Not prime because it's a multiple of 6)
 c  n = 6k  1. (Possibly prime)
 d  n = 1. (Not prime)
 e  n = 6k + 5. (Possibly prime)
 f  n = 6(k + 1). (Not prime because it's a multiple of 6)
   Therefore for each k >= 2, we need to count how many numbers
+  * Therefore for each k >= 2, we need to count how many numbers
 in the set {6k  1, 6k + 5, 12k  7} are prime.
 Example of an edge cell n = 19 in ring 2:
 37
diff git a/python/p071.py b/python/p071.py
index dbe68db..3ba553e 100644
 a/python/p071.py
+++ b/python/p071.py
@@ 14,11 +14,11 @@ if sys.version_info.major == 2:
# We consider each (integer) denominator d from 1 to 1000000 by brute force.
# For a given d, what is the largest integer n such that n/d < 3/7?
#
# * If d is a multiple of 7, then the integer n' = (d / 7) * 3 satisfies n'/d = 3/7.
+#  If d is a multiple of 7, then the integer n' = (d / 7) * 3 satisfies n'/d = 3/7.
# Hence we choose n = n'  1 = (d / 7) * 3  1, so that n/d < 3/7.
# Since (d / 7) * 3 is already an integer, it is equal to floor(d * 3 / 7),
# which will unifie with the next case. Thus n = floor(d * 3 / 7)  1.
# * Otherwise d is not a multiple of 7, so choosing n = floor(d * 3 / 7)
+#  Otherwise d is not a multiple of 7, so choosing n = floor(d * 3 / 7)
# will automatically satisfy n/d < 3/7, and be the largest possible n
# due to the definition of the floor function.
#
diff git a/python/p145.py b/python/p145.py
index 3676c37..de19846 100644
 a/python/p145.py
+++ b/python/p145.py
@@ 15,10 +15,10 @@
# reversed number does not have leading zeros.
#
# Consider different cases for the number of digits n (from 1 to 9, but the arguments apply generally):
# * n = 1:
+#  n = 1:
# Clearly there are no solutions because the last digit is always even.
#
# * n = 0 mod 2:
+#  n = 0 mod 2:
# We begin by proving that when a number is "reversible", the process of adding
# the number to the reverse of itself will involve no carries in the arithmetic.
# Normally a rigorous proof would require the use of mathematical induction,
@@ 70,7 +70,7 @@
# (9,0).
# Therefore by combinatorics, there are 20 * 30^(n/2  1) reversible ndigit numbers when n is even.
#
# * n = 1 mod 2:
+#  n = 1 mod 2:
# Let's illustrate what happens with a 7digit number abcdefg:
# 0101010
# abcdefg
@@ 93,7 +93,7 @@
# This is why we get the alternating pattern of carries in the adding process.
#
# The rest of the work is to enumerate the possibilities for each type of digit(s) in the number:
# * Pairs of digits which take no carry and must generate a carry (20 choices):
+#  Pairs of digits which take no carry and must generate a carry (20 choices):
# (9,8), (9,6), (9,4), (9,2),
# (8,9), (8,7), (8,5), (8,3),
# (7,8), (7,6), (7,4),
@@ 103,7 +103,7 @@
# (3,8),
# (2,9).
# Note that the first and last digits fall into this category, and there are no 0s at all.
# * Nonmiddle pairs of digits which take a carry and generate no carry (25 choices):
+#  Nonmiddle pairs of digits which take a carry and generate no carry (25 choices):
# (0,0), (0,2), (0,4), (0,6), (0,8),
# (1,1), (1,3), (1,5), (1,7),
# (2,0), (2,2), (2,4), (2,6),
@@ 113,7 +113,7 @@
# (6,0), (6,2),
# (7,1),
# (8,0).
# * Middle single digit, which takes a carry and generates no carry (5 choices): 0, 1, 2, 3, 4.
+#  Middle single digit, which takes a carry and generates no carry (5 choices): 0, 1, 2, 3, 4.
# All in all, there are 5 * 20^((n + 1)/4) * 25^((n  3)/4) = 100 * 500^((n  3)/4)
# reversible ndigit numbers when n = 3 mod 4.
def compute():

2.21.0