Processing math: 20%

Sunday, April 27, 2025

More large gaps in Euclid's orchard

The fifth largest pair of adjacent gaps in this range are on either side of what angle up from the x-axis?

If use the same Python script shown earlier in the Classic answer, using the value of k=6 in the Python code, we get that for large enough values of R, the next few largest pair of adjacent gaps occur at the following bearings, respectively: θ2=tan1(13)18.434948823θ3=tan1(23)33.690067526θ4=tan1(14)14.036243468. Through now, we still maintain that these are corresponding to the next highest peaks of Thomae's function at x2=34,x3=35 and x4=45, respectively. However, continuing one step further, we see that for sufficiently large values of R, the fifth largest pair of adjacent gaps occurs at θ5=tan1(34)36.869897649, which in fact skips over the next highest Thomae's function value of ˜x=56 in favor of x5=47. Don't feel too bad for ˜x=56, since it is equivalent to the bearing θ6=tan1(15)11.309932474, which is in fact the bearing around which you can find the next largest adjacent pair gaps. Perhaps you could still feel bad for Thomae's function's explanatory powers, though.

Searching for large pairs of adjacent gaps in Euclid's orchard

You are at the point (0,0) on the coordinate plane. There is a tree at each point with nonnegative integer coordinates, such as (5,6), (0,7), and (9,1). The trees are very thin, so that they only obstruct trees that are directly behind them. For example, the tree at (2,2) is not visible, as it is obscured by the tree at (1,1).

Now, you can’t see infinitely far in this forest. You’re not sure exactly how far you can see, but it’s pretty dang far. As you look around, you can make out very narrow angular gaps between the trees. The largest gaps are near the positive x-axis and the positive y-axis. After those, the next largest pair of gaps is on either side of the tree at (1,1), 45 degrees up from the x-axis.

Consider the view between 0 and 45 degrees up from the x-axis. The next largest pair of adjacent gaps in this range are on either side of what angle up from the x-axis?

First, let's note that our forest is akin to what's known as Euclid's orchard, which assumes that each tree is the three dimensional line segment from (m,n,0) to (m,n,1) for (m,n)N2. Well, it turns out that if you as an observer at (0,0) are viewing this orchard along the line y=x, that either the tree whose base is at (m,n) is blocked by another tree if gcd(m,n)>1, or the height of the tree will appear to be at height 1m+n if gcd(m,n)=1. Therefore, we can associate any visible tree at (m,n) with the point x=x(m,n)=mm+n(0,1) and then its height will be given by Thomae's function defined by T(x)={1q,if x=pq for pZ, qN and gcd(p,q)=1;0,otherwise. Since we cannot actually see infinitely far into Euclid's orchard, let's assume that we can only see a tree if its base is at (m,n)N2 and m2+n2R2 for some R1. Therefore, since R2=max the corresponding approximated Thomae's function is T_R(x) = \begin{cases} \frac{1}{q}, &\text{if $x = \frac{p}{q}$ for $p \in \mathbb{Z},$ $q \in \mathbb{N}$, $\textsf{gcd}(p,q) = 1$ and $q \leq R\sqrt{2}$;}\\ 0, &\text{otherwise.}\end{cases}.

Now Thomae's function is fascinating with lots of pathology (e.g., integrable, nowhere differentiable, continuous at each irrational, discountinuous at each rational, etc.). However, here we are interested in using adjacent discontinuities of the approximate Thomae's function but measuring the distances between them in some completely different way, since ultimately we are measuring the angle between the x-axis and the point (m,n), which has much more to do with \frac{n}{m} than \frac{m}{m+n}. So, though I would love to have this problem yield a deep dive into Thomae's function, instead, let's just brute force throw a computer at this problem and see what comes out, since

We need to just implement the following pseudocode procedure: (1) enumerate all of the visible trees, for instance, \textsf{trees} = \left[ (m,n) \mid n \in \{1, \dots, R\}, m \in \{n, \dots, R \}, \textsf{gcd}(m,n) = 1, m^2 + n^2 \leq R^2 \right]; (2) convert each tree to its bearing (angle above the x-axis), that is \textsf{bearings} = \left[ \textsf{arctan2(n,m)} \mid (m,n) \in \textsf{trees} \right]; (3) order the values of \textsf{bearings} in ascending order and let \textsf{gaps} be the corresponding gaps between adjacent trees; and (4) take an \textsf{argsort} of \textsf{gaps} to pull out the location of the largest gaps.

Below is a Python implementation of this pseudocode:

import numpy as np

def get_trees(R):
    return [ (m, n) for n in range(R) for m in range(n, R) if np.gcd(m,n) == 1 and m*m + n*n <= R*R ]

def get_tree_bearings(R):
    bearings = [ np.arctan2(n, m) for (m, n) in get_trees(R) ]
    return sorted(bearings), np.argsort(bearings)

def get_big_gap_bearings(R,k=7):
    trees = get_trees(R)
    bearings, orders = get_tree_bearings(R)
    gaps = [ x - y for x, y in zip(bearings[1:], bearings[:-1])]
    big_gaps = np.argsort(gaps)[-2*k:]
    return [(trees[orders[i]], trees[orders[i+1]]) for i in big_gaps]

For the Classic problem we notice that for k=2 and various values of R = 10, 20, 50, 100, 200, 500, 1000, that we confirm that the largest gap always is next to the x-axis, followed by the gap nearest to the tree at (1,1), then the next largest pair of adjacent gaps is on either side of the tree at (2,1), that is, with bearing \theta^* = \tan^{-1} \left(\frac{1}{2}\right) \approx 26.565051177\dots^\circ. This interestingly, though still mysteriously since I'm not totally sold on the ability to directly infer much of anything from Thomae's function, is equivalent to the second tallest peak of Thomae's function at x^* = 2/3.

Sunday, April 20, 2025

Extra credit hammer throwing

Instead of playing to 3 points, now the first player to 5 points wins the match.

Good news (again)! You have won the first hole, and now lead 1-0. What is your probability of winning the match?

This game will have the same recurrence relationship, but the initial conditions will be \tilde{w}(s_1, s_2) = \begin{cases} 1, &\text{if $s_1 \geq 5 \gt s_2;$}\\ 0, &\text{if $s_1 \lt 5 \leq s_2.$}\end{cases} Since \tilde{w}(s_1,s_2) = w(s_1-2,s_2-2), we automatically have \tilde{w}(4,4) = \tilde{w}(4,3) = \tilde{w}(3,4) = \tilde{w}(3,3) = \frac{1}{2} along with \tilde{w}(4,2) = \tilde{w}(3,2) = \frac{3}{4} and \tilde{w}(2,3) = \tilde{w}(2,4) = \frac{1}{4}. We also have \tilde{w}(4,1) = \tilde{w}(3,1) = \frac{3}{4}, \tilde{w}(1,4) = \tilde{w}(1,3) = \frac{1}{4}, \tilde{w}(4,0) = \tilde{w}(3,0) = \frac{7}{8}, \tilde{w}(1,1) = \tilde{w}(2,2) = \tilde{w}(1,2) = \tilde{w}(2,1) = \frac{1}{2}, and \tilde{w}(2,0) = \frac{11}{16}.

Finally, we arrive at the probability of winning the match to 5 points if you each are playing optimally as \begin{align*} \tilde{w}(1,0) &= \max_u \min_v \left[ uv \frac{\frac{7}{8} + \frac{1}{2}}{2} + (1-u)(1-v) \frac{\frac{11}{16} + \frac{1}{2}}{2} \right. \\ &\quad\quad\quad\quad\quad\left. + u(1-v) \min \left\{ \frac{\frac{7}{8} + \frac{1}{2}}{2}, \frac{11}{16} \right\} + (1-u)v \max \left\{\frac{\frac{11}{16} + \frac{1}{2}}{2}, \frac{11}{16} \right\} \right] \\ &= \max_u \min_v \left[ \frac{11}{16} uv + \frac{19}{32} (1-u)(1-v) + \frac{11}{16} u(1-v) + \frac{11}{16} (1-u)v \right] \\ &= \max_u \min_v \left[ \frac{19}{32} + \frac{3}{32} u + \frac{3}{32} v - \frac{3}{32} uv \right] = \frac{11}{16},\end{align*} with optimizers u^* = 1, v^* = 0.

Isn't hammer throw was a field sport?

You and your opponent are competing in a golf match. On any given hole you play, each of you has a 50 percent chance of winning the hole (and a zero percent chance of tying). That said, scorekeeping in this match is a little different from the norm.

Each hole is worth 1 point. Before starting each hole, either you or your opponent can “throw the hammer.” When the hammer has been thrown, whoever did not throw the hammer must either accept the hammer or reject it. If they accept the hammer, the hole is worth 2 points. If they reject the hammer, they concede the hole and its 1 point to their opponent. Both players can throw the hammer on as many holes as they wish. (Should both players decide to throw the hammer at the exact same time—something that can’t be planned in advance—the hole is worth 2 points.)

The first player to reach 3 points wins the match. Suppose all players always make rational decisions to maximize their own chances of winning.

Good news! You have won the first hole, and now lead 1-0. What is your probability of winning the match?

Let's define your win probability as the function w : \mathbb{N}^2 \to [0,1], so that w(s_1, s_2) is the probability of winning the match given that the current score is s_1 points for you and s_2 points for your opponent, assuming that you are both playing perfectly rationally, maximizing you own chances of winning. Let u be the indicator of whether or not you throw the hammer when the score is (s_1, s_2). Let v be the indicator of whether or not your opponent throws the hammer when the score is (s_1,s_2). Then we can define the recursion formula \begin{align*} w(s_1,s_2) &= \max_{u \in \{0,1\}} \min_{v \in \{0,1\}} \left[uv \frac{ w(s_1+2, s_2) + w(s_1, s_2 + 2) }{2} \right. \\ &\quad\quad\quad + (1-u)(1-v) \frac{ w(s_1 + 1,s_2) + w(s_1, s_2 + 1)}{2} \\ &\quad\quad\quad\quad + u(1-v) \min \left\{ \frac{w(s_1+2, s_2) + w(s_1, s_2 + 2)}{2}, w(s_1+1,s_2) \right\} \\ &\quad\quad\quad\quad\quad \left.+(1-u)v \max \left\{ \frac{w(s_1+2, s_2) + w(s_1, s_2+2)}{2}, w(s_1, s_2+1) \right\} \right],\end{align*} where the coefficients of u(1-v) and (1-u)v, represent the optimal choice of whether or not to accept or reject the hammer, by your opponent and you, respectively. As boundary conditions, we have w(s_1,s_2) = \begin{cases} 1, &\text{if $s_1 \geq 3 \gt s_2$;}\\ 0, &\text{if $s_1 \lt 3 \leq s_2.$}\end{cases}

In particular, we see that for instance \begin{align*}w(2,2) &= \max_u \min_v \left[ uv \frac{ 1 + 0}{2} + (1-u)(1-v) \frac{1 + 0}{2} + u(1-v) \min \left\{ \frac{1+0}{2}, 1 \right\} + (1-u)v \max \left\{ \frac{1+0}{2}, 0 \right\}\right] \\ &= \max_u \min_v \frac{1}{2} = \frac{1}{2}.\end{align*} We also find that \begin{align*}w(1,2) &= \max_u \min_v \left[ uv \frac{1+0}{2} + (1-u)(1-v) \frac{\frac{1}{2} + 0}{2} + u(1-v) \min \left\{ \frac{1+0}{2}, \frac{1}{2} \right\} + (1-u)v \max \left\{ \frac{1+0}{2}, 0 \right\} \right] \\ &= \max_u \min_v \left[\frac{1}{4} + \frac{1}{4}u + \frac{1}{4}v - \frac{1}{4}uv\right] = \frac{1}{2},\end{align*} with optimizers u^*=1 and v^*=0. Similarly, w(2,1) = \frac{1}{2}, as well.

Working our way backward we see that w(2,0) = \frac{3}{4}, w(1,1) = \frac{1}{2} and w(0,2) = \frac{1}{4}. Therefore, we can finally arrive at the probability of winning given that you and your opponent play optimally and that the current score is 1-0 is \begin{align*}w(1,0) &= \max_u \min_v \left[ uv \frac{1 + \frac{1}{2}}{2} + (1-u)(1-v) \frac{\frac{3}{4} + \frac{1}{2}}{2} + u(1-v) \min \left\{ \frac{1+\frac{1}{2}}{2}, \frac{3}{4} \right\} + (1-u) v \max \left\{ \frac{1 + \frac{1}{2}}{2}, \frac{1}{2} \right\} \right] \\ &= \max_u \min_v \left[ \frac{5}{8} + \frac{1}{8} u + \frac{1}{8} v - \frac{1}{8} uv \right] = \frac{3}{4},\end{align*} with optimizers u^*=1 and v^*=0.

Monday, April 14, 2025

Paying attention to the hints

Dean has three colors of the hibiscus: red, orange, and yellow. He wants to plant them in a straight hedge of shrubs (each of which is one color) so that the order appears somewhat random, but not truly random. More specifically, he wants the following to be true:

  • No two adjacent shrubs have the same color.
  • No ordering of three consecutive shrubs appears more than once in the hedge.

What is the greatest number of shrubs Dean’s hedge can contain?

I should have picked up on the otherwise extraneous information regarding Rivka Lipkovitz's interest in the base-7 Doomsday algorithm to divine that my Ore's theorem base upper bound was not exactly the sharpest bound in the shed. Well, you can't fool me again! I know that since I did indeed like the previous week's Fiddler involved Hamiltonian cycles, that somehow this one will too ....

So let's design Dean's hedge instructions as a directional graph. Let O denotes an orange hibiscus, R a red one, and Y a yellow one. Then a triplet v = (v_1,v_2,v_3) with v_i \in \{O,R,Y\} with v_2 \ne v_1 and v_3 \ne v_2 is one of the possible orderings of three consecutive shrubs that satisfies both of the conditions. Let V = \{ ORO, ORY, OYO, OYR, ROR, ROY, RYO, RYR, YOR, YOY, YRO, YRY \} be the set of vertices. We can draw a directional edge between v_1 and v_2 if the first two characters of v_2 are the last two characters of v_1, so for instance, there is an edge from RYR to YRO but not one that starts at YRO and ends at RYR. Thus all possible edges are E = \{ (v_1, v_2) \mid v_{12} = v_{21}, v_{13} = v_{22} \}.

Sure enough, there is a Hamiltonian cycle on the graph G = (V,E) covering all 12 possible vertices, which gives a maximal Dean-approved hibiscus hedge length of 14 shurbs (count the first three shrubs of the initial vertex, then each subsequent vertex only adds one new shrub so 3 + 11 = 14). One possible instance of this Hamiltonian cylce is given by \begin{align*} ORO \to ROY \to OYO &\to YOR \to ORY \to RYO \to YOY\\ &\to OYR \to YRY \to RYR \to YRO \to ROR \to ORO,\end{align*} which when put altogether gives a hedge denoted as OROYORYOYRYROR.

Monday, April 7, 2025

Striking Ore while digging into Lipkovitz's Hamiltonian puzzle

A teacher is handing out candy to his students. He abides by the following rules:

  • He hands out candy to groups of three students (i.e., “trios”) at a time. Each member of the trio gets one piece of candy.
  • Each unique trio can ask for candy, but that same trio can’t come back for seconds. If students in the trio want more candy, they must return as part of a different trio.
  • When a trio gets candy, the next trio can’t contain any students from that previous trio.

It turns out that every possible trio can get a helping of candy together. What is the smallest class size for which this is possible?

Obviously, I assume that we are not talking about the trivial case of N=3 students, because, ... lame!

So let's assume that there are N \gt 3 students. Then there will be M = \binom{N}{3} = \frac{1}{6}N(N-1)(N-2) possible trios in the class. Let's assume that the set V = \{ v_1, v_2, \dots, v_M \} enumerates all such trios. Based on the teacher's final condition, we can see that if v_i and v_j share a common student, then v_j cannot be the next trio to ask if v_i has just received candy. Let's define a set of edges on the vertex set E = \{ (v_i, v_j) \in V \times V \mid j \gt i, v_i \cap v_j = \emptyset \}, that is, if the trio v_i could immediately follow the trio v_j (or vice versa), then there is an edge between v_i and v_j. We will call vertices v_i and v_j adjacent if there is an edge e \in E connecting v_i and v_j. Let's define the graph \mathcal{G} = (V, E). Note that we define the degree of a vertex, denoted \delta(v), to be the number of vertices w \in V that are adjacent to v, that is, \delta(v) = \# \{ w \in V \mid e = (v,w) \in E \}.

Since it turns out that every possible trio can get a helping of candy together, but based on the second condition each trio can only ask for candy once, then there must be some path that on \mathcal{G} that visits each vertex exactly once. This type of path is known in graph theory as a Hamiltonian path. A graph is called Hamiltonian if it admits a Hamiltonian path starts and ends at adjacent vertices. The Norwegian graph theorist Øystein Ore provided the following sufficient condition for a graph to Hamiltonian based on the degrees of its vertices:

Ore's Theorem: A graph \mathcal{G} = (V, E) with |V| = n is Hamiltonian if for every pair of non-adjacent vertices v, w \in V, \delta(v) + \delta(w) \geq n.

Let's note that for our graph \mathcal{G}_N, since any vertex v is adjacent to any other trio made up of distinct students, we have \delta(v) = \binom{N-3}{3} = \frac{1}{6} (N-3)(N-4)(N-5) = \frac{N^3 -12N^2 + 47N - 60}{6}. So from an application of Ore's theorem, whenever M = \frac{N^3-3N^2+2N}{6} \leq 2 \frac{N^3 -12N^2 +47N - 60}{6} or equivalently, whenever N^3 - 21N^2 +92N -120 \geq 0, then \mathcal{G} is Hamiltonian. Since the real root of the polynomial p(t) = t^3 -21t^2 +92t -120 is at t^* \approx 15.59.... we have that whenever N \geq 16, then every possible trio can have a helping of candy together.

Monday, March 31, 2025

Boosting busts more seeds in bigger tourneys

Instead of four teams, now there are 2^6, or 64, seeded from 1 through 64. The power index of each team is equal to 65 minus that team’s seed.

The teams play in a traditional seeded tournament format. That is, in the first round, the sum of opponents’ seeds is 2^6+1, or 65. If the stronger team always advances, then the sum of opponents’ seeds in the second round is 2^5+1, or 33, and so on.

Once again, the underdog in every match gets a power index boost B, where B is some positive non-integer. Depending on the value of B, different teams will win the tournament. Of the 64 teams, how many can never win, regardless of the value of B?

After setting up the 64 team bracket, we can choose various values for B and then compute the winners directly. Since the outcome will remain the same for all non-integer values in (\lfloor B \rfloor, \lceil B \rceil), we need only select a total of 64 values, e.g., b+0.5, for b = 0, 1, \dots, 63. The summary of the outcomes of the 64 team tournament bracket are in the table below. We note that there are 27 seeds (namely, 7, 13-15, and 25-47) who never win the tournament. Most unlucky out of each of them are 7, 15 and 47, each of which have sets of B of measure 3 for which they will end up the runner up of the tournament, though they will never win it.

B Winning Seed Runner Up
(0,1) 1 2
(1,2) 1 3
(2,3) 3 1
(3,4) 2 1
(4,5) 6 5
(5,6) 5 3
(6,7) 5 3
(7,8) 4 3
(8,9) 12 11
(9,10) 11 9
(10,11) 11 9
(11,12) 10 9
(12,13) 10 9
(13,14) 9 7
(14,15) 9 7
(15,16) 8 7
(16,17) 24 23
(17,18) 23 21
(18,19) 23 21
(19,20) 22 21
(20,21) 22 21
(21,22) 21 19
(22,23) 21 19
(23,24) 20 19
(24,25) 20 19
(25,26) 19 17
(26,27) 19 17
(27,28) 18 17
(28,29) 18 17
(29,30) 17 15
(30,31) 17 15
(31,32) 16 15
(32,33) 48 47
(33,34) 49 47
(34,35) 49 47
(35,36) 50 49
(36,37) 50 49
(37,38) 51 49
(38,39) 51 49
(39,40) 52 51
(40,41) 52 51
(41,42) 53 51
(42,43) 53 51
(43,44) 54 53
(44,45) 54 53
(45,46) 55 53
(46,47) 55 53
(47,48) 56 55
(48,49) 56 55
(49,50) 57 55
(50,51) 57 55
(51,52) 58 57
(52,53) 58 57
(53,54) 59 57
(54,55) 59 57
(55,56) 60 59
(56,57) 60 59
(57,58) 61 59
(58,59) 61 59
(59,60) 62 61
(60,61) 62 61
(61,62) 63 61
(62,63) 63 61
\gt 63 64 63