Saturday, 31 May 2025

Self Avoiding Walks

In my previous post titled Random Walks, I made mention of self-avoiding walks and for this post I asked Gemini 2.5 Pro to implement the following program:

Write a program in Python that will generate and display a random but self avoiding walk on a square grid of points. The size of the grid can be 100 x 100 points but this should be easily modifiable. The walk should start at the bottom left hand side and proceed to the top right hand side. Each step can be up or down from one point to the next or left or right from one point to the next but movement is contrained within the grid of points. The number of steps required to complete the walk should be prominently displayed at the top or bottom of the display.

It dutifully did this and here is the Canvas link. Here was Gemini's thinking about the desired program.

Okay, I'll provide you with a Python program that generates and displays a random self-avoiding walk on a square grid. This program uses a recursive backtracking algorithm to find a path from the bottom-left corner to the top-right corner. The grid size is easily modifiable.

Here's how the program works:

  1. Grid and Path Representation: The grid is implicitly defined by its size. The path is stored as a list of (x, y) coordinate tuples.
  2. Self-Avoiding Walk Generation:
    • It starts at (0,0) (bottom-left).
    • The target is (grid_size-1, grid_size-1) (top-right).
    • A recursive function attempts to find a path:
      • It marks the current cell as visited and adds it to the path.
      • If the current cell is the target, the path is found.
      • Otherwise, it randomly shuffles the possible directions (Up, Down, Left, Right).
      • For each valid direction (within bounds and not previously visited in the current path), it makes a recursive call.
      • If a recursive call returns success, the path is propagated up.
      • If all directions from the current cell lead to dead ends, it backtracks by removing the cell from the path and unmarking it as visited.
    • Due to the potential for deep recursion, especially on large grids (like 100x100), the program attempts to increase Python's recursion limit. Note that for very large grids, this process can still be computationally intensive and take some time.
  3. Display:
    • matplotlib is used to visualize the walk.
    • The path is plotted on the grid.
    • Start and end points are highlighted.
    • The number of steps taken is displayed in the plot title.

I will now generate the Python code for you.

Self-Avoiding Random Walk Generator

This Python script defines two main functions: generate_self_avoiding_walk to create the path and display_walk to visualize it using matplotlib.

To use this code:

  1. Save it as a Python file (e.g., saw_generator.py).
  2. Make sure you have matplotlib installed (pip install matplotlib).
  3. Run it from your terminal: python saw_generator.py.
  4. You can easily change the GRID_SIZE variable in the if __name__ == "__main__": block to generate walks on grids of different sizes. Keep in mind that larger grids (e.g., 100x100) will take significantly longer to compute and may require a high recursion limit, which the script attempts to set.

The generated plot will show the random walk, and the title will include the number of steps taken.

I should try to implement this program myself using SageMathCell. Running the program on SageMathCell using only for a 20m x 20 grid will often cause it to time out and even in my Jupyter notebook I often needed to terminate the process because it was taking too long. However, the program often generates a walk quite quickly and Figures 1 and 2 show typical outputs.


Figure 1: permalink


Figure 2: permalink

The difference between Figures 1 and 2 in this post compared to Figure 9 in my previous post is that the latter traverses every point in the grid and not just a random selection of them. Gemini will write a program to do this but as it explains:
Finding a Hamiltonian path is an NP-complete problem. This means that for larger grids, the time required to find such a path can grow extremely rapidly. The provided recursive backtracking algorithm will explore many possibilities. For a small grid (e.g., 3x3, 4x4, maybe 5x5), it might find a solution in a reasonable time.

Here is a Canvas link to the code. Figure 3 shows a typical output using a 4 x 4 grid.


Figure 3

Friday, 30 May 2025

Random Walks

On the 20th of December 2018, I uploaded a post titled Random Walks in which I looked at random walks within a grids of fixed size. For example, consider a 4 x 4 grid of points where the walk starts at (0, 0) and finishes at (4, 4). Movement can be vertical (up or down) or horizontal (left or right) but is confined to the grid. Diagonal movement in one step is not possible. See Figure 1.


Figure 1

I created a program (permalink) to simulate 1000 random walks and calculate the median of the number of steps required to travel from (0, 0) to (4, 4). It turned out to be about 60 steps. In this post, I looked at other 2-D grid sizes and also random walks in 3 dimensions with varying grid sizes (permalink). See Figure 2.


Figure 2

This present post was inspired by a Cliff Pickover tweet. See Figure 3.


Figure 3

I created a SageMath program (permalink) to simulate a 2-D random walk starting at the origin and concluding at the origin (if it is ever reached). Movement can be up or down one step and\or left or right one step, so diagonal movement is possible. See Figure 4.

Figure 4

I set a step limit of 100,000 and quite often the walk had not returned to the origin by then. See Figure 5.


Figure 5

At other times, it would return to the origin within the limit imposed. See Figure 6 and Figure 7.


Figure 6


Figure 7

Often the walk will end after a few dozen steps or less and these shorter walks are by far the most common. See Figure 8.


Figure 8

This was just an introductory look at 2-D random walks upon an infinite grid and there's much more to explore. As an example, Figure 9 shows another tweet from Cliff Pickover regarding SAW (Self Avoiding Walks).


Figure 9

Bertrand's Box Paradox

 I came across the following problem in my Inbox:

I have placed three coins inside a bag. The first coin has heads on both of its sides, the second coin has tails on both of its sides, and the third coin has heads on one side and tails on the other side.

I randomly take one coin from the bag. I open my hand and look at it. I notice that the side facing me is heads. What is the probability that the other side of the coin is also heads?

A. Less than 50%, B. More than 50% or C. Exactly 50%

I went for the exactly 50% option, which unfortunately proved to wrong. The correct answer was more than 50% and the following explanation was offered:

This puzzle is a variant of the Bertrand’s box paradox, and the exact answer is that there is a 2/3rds chance that the other side of the coin is also heads. However, many people answering this question intuitively say there is a 50% chance.

The best way to think of this problem is in terms of sides, not individual coins that have two sides. We are told that there are three heads sides in total. The heads side that you viewed could be any of the three heads sides in the bag. Two of the three heads sides in the bag have heads on the other side, therefore there is a 2/3rds chance that the other side of the coin you viewed is also heads.

I was thus prompted to find out more about Bertrand's Box Paradox and this is what Gemini had to say:

Bertrand's Box Paradox is a classic problem in probability theory that often trips people up because their intuition leads them to the wrong answer. It's a "veridical paradox," meaning the solution is indeed counter-intuitive but demonstrably correct.

Here's the setup:

Imagine you have three identical boxes:

  1. Box 1 (GG): Contains two gold coins.

  2. Box 2 (SS): Contains two silver coins.

  3. Box 3 (GS): Contains one gold coin and one silver coin.

You randomly choose one of the three boxes. Then, you randomly draw one coin from that chosen box.

The Paradoxical Question:

If the coin you drew is gold, what is the probability that the other coin remaining in that same box is also gold?

Why it's confusing (the intuitive, but wrong, answer):

Many people would intuitively say 1/2 (50%). Their reasoning often goes like this:

"Since I drew a gold coin, I know I didn't pick Box 2 (SS). So, it must be either Box 1 (GG) or Box 3 (GS). Since there are only two possibilities, and one of them (GG) means the other coin is gold, it's 1/2."

Why this reasoning is flawed:

The flaw lies in assuming that Box 1 (GG) and Box 3 (GS) are equally likely given that you drew a gold coin. This is not true.

The Correct Solution (and why it's 2/3):

Let's break down the possibilities more systematically. There are a total of 6 coins (2 gold, 2 silver, 1 gold, 1 silver). Each coin has an equal chance of being drawn initially.

Consider all the ways you could draw a gold coin:

  1. From Box 1 (GG): You could draw the first gold coin, and the other coin is gold. (Let's call this G1a)

  2. From Box 1 (GG): You could draw the second gold coin, and the other coin is gold. (Let's call this G1b)

  3. From Box 3 (GS): You could draw the gold coin, and the other coin is silver. (Let's call this G3)

These are the only three ways you could have drawn a gold coin. Each of these three "initial gold coin draws" is equally likely.

Now, let's look at what the other coin in the box would be for each of these three equally likely scenarios:

  1. If you drew G1a (from Box 1), the other coin is gold.

  2. If you drew G1b (from Box 1), the other coin is gold.

  3. If you drew G3 (from Box 3), the other coin is silver.

Out of the three equally likely ways to draw a gold coin, two of those ways result in the other coin also being gold.

Therefore, the probability that the other coin in the box is also gold is 2/3.

Analogy to help understand:

Imagine you have six coins laid out on a table:

  • G1 G2 (from Box 1)

  • S1 S2 (from Box 2)

  • G3 S3 (from Box 3)

You close your eyes and pick one coin. You open your hand and it's gold. Which gold coin did you pick? It could be G1, G2, or G3.

  • If you picked G1, the other coin in its pair (from Box 1) is G2 (gold).

  • If you picked G2, the other coin in its pair (from Box 1) is G1 (gold).

  • If you picked G3, the other coin in its pair (from Box 3) is S3 (silver).

Since G1, G2, and G3 were all equally likely to be picked as your first gold coin, and two out of those three scenarios lead to the other coin being gold, the probability is 2/3.

The key takeaway is that when you draw a gold coin, you gain information that changes the probabilities of which box you initially chose. The box with two gold coins is twice as likely to yield a gold coin on the first draw compared to the box with one gold and one silver coin.

Thursday, 29 May 2025

Xenodrome Pairs, Triplets Etc.

27815, the number associated with my diurnal age today, is one of those numbers for which an interesting property is hard to come by. However, I did notice that the number was a xenodrome in both base 10 and base 9 (42135). A little further investigation revealed that 27816 also shared this property. That got me thinking about how often pairs of such numbers occur. Now I've written about xendromes before in posts titled Xenodromes and Xenodrome Probabilities in which I've looked at numbers that remain xenodromes in various bases but so far I've not looked at groupings of numbers by pairs, triplets, quadruplets etc. with properties relating to xenodromes.

In my Bespoken for Sequences database, I've listed the following sequence of numbers:Smaller of a pair of consecutive numbersthat are xenodromes in base 10 and base 9Between 27815 and 40000, there are 282 numbers with this property (permalink):

27815, 27834, 27835, 27845, 27860, 27950, 27953, 27960, 28013, 28016, 28134, 28169, 28195, 28196, 28314, 28346, 28356, 28364, 28395, 28456, 28495, 28509, 28536, 28563, 28573, 28590, 28609, 28670, 28914, 28934, 28935, 28963, 29015, 29016, 29053, 29075, 29084, 29085, 29103, 29134, 29147, 30147, 30148, 30156, 30157, 30186, 30194, 30195, 30196, 30457, 30458, 30467, 30528, 30548, 30561, 30591, 30691, 30724, 30725, 30751, 30764, 30814, 30825, 30851, 30924, 30925, 31024, 31025, 31048, 31057, 31086, 31094, 31095, 31096, 31097, 31257, 31258, 31259, 31267, 31268, 31284, 31294, 31475, 31586, 31604, 31607, 31608, 31806, 31824, 31825, 31826, 31859, 31905, 31906, 31907, 32018, 32104, 32108, 32159, 32189, 32496, 32508, 32509, 32546, 32580, 32589, 32590, 32607, 32608, 32609, 32648, 32657, 32670, 32689, 32690, 32697, 32907, 32947, 32960, 32964, 34027, 34058, 34085, 34086, 34091, 34095, 34127, 34157, 34158, 34175, 34185, 34206, 34215, 34275, 34278, 34279, 34296, 34297, 34560, 34567, 34568, 34569, 34578, 34620, 34650, 34658, 34761, 34785, 34815, 34820, 34905, 34917, 34926, 35016, 35017, 35047, 35097, 35169, 35196, 35197, 35208, 35216, 35217, 35479, 35486, 35496, 35641, 35809, 35826, 35890, 35891, 35916, 35917, 35946, 35961, 35970, 35971, 35980, 35981, 36018, 36027, 36028, 36208, 36209, 36214, 36218, 36270, 36278, 36279, 36280, 36289, 36290, 37195, 37204, 37245, 37285, 37294, 37295, 37458, 37459, 37485, 37495, 37519, 37520, 37528, 37568, 37819, 37820, 37845, 37864, 37890, 37891, 37920, 37945, 37964, 37981, 38015, 38024, 38045, 38046, 38064, 38105, 38106, 38124, 38145, 38159, 38169, 38205, 38206, 38240, 38249, 38250, 38259, 38260, 38405, 38406, 38415, 38420, 38469, 38649, 38670, 38674, 38694, 38701, 38720, 38724, 38751, 38760, 38904, 38916, 39015, 39016, 39017, 39024, 39025, 39026, 39124, 39125, 39126, 39186, 39205, 39206, 39207, 39215, 39216, 39240, 39260, 39481, 39485, 39540, 39541, 39571, 39580, 39604, 39701, 39715, 39724, 39764, 39805, 39814, 39845, 39846

There are 69  triplets in the same range (permalink):Smallest of a triplet of consecutive numbersthat are xenodromes in base 10 and base 927834, 28195, 28934, 29015, 29084, 30147, 30156, 30194, 30195, 30457, 30724, 30924, 31024, 31094, 31095, 31096, 31257, 31258, 31267, 31607, 31824, 31825, 31905, 31906, 32508, 32589, 32607, 32608, 32689, 34085, 34157, 34278, 34296, 34567, 34568, 35016, 35196, 35216, 35890, 35916, 35970, 35980, 36027, 36208, 36278, 36279, 36289, 37294, 37458, 37519, 37819, 37890, 38045, 38105, 38205, 38249, 38259, 38405, 39015, 39016, 39024, 39025, 39124, 39125, 39205, 39206, 39215, 39540, 39845

An example is the xenodrome 27834 with 27835 and 27836 also xenodromes. The base 9 equivalents 42156, 42157 and 42158 are also xenodromes.

There are 13 quadruplets in the same range (permalink):Smallest of a quaduplet of consecutive numbersthat are xenodromes in base 10 and base 930194, 31094, 31095, 31257, 31824, 31905, 32607, 34567, 36278, 39015, 39024, 39124, 39205

An example is the xenodrome 30194 with 30195, 30196 and 30197 also xenodromes. The base 9 equivalents 45368, 45370, 45371 and 45372 are also xenodromes. 

There is only one quintuplet in the range and that is 31094. Here we see that 31094, 31095, 31096, 31097 and 31098 are all xenodromes as are their base 9 equivalents 46578, 46580, 46581, 46582 and 46583.

Sunday, 25 May 2025

More on A + B + C = D and A + B = C

In my previous post titled A + B + C = D, I generated a list of 44 "d" numbers with the property that:a+b+c=dwhere a, b, c and d share the same digits and a<b<c. The list of such numbers, up to 40000, is:

4617, 4851, 5103, 5184, 5913, 6021, 6129, 6192, 6219, 6291, 6921, 7182, 7281, 7416, 7614, 8145, 8154, 8253, 8325, 8451, 8514, 8523, 8541, 9135, 9216, 9234, 9324, 9612, 9621, 31860, 31905, 36171, 36711, 37116, 37161, 38061, 38106, 38151, 38214, 38511, 39051, 39105, 39411, 39501

In my post I noted the significant gap between sequence member 9621 and sequence member 31860. This was unfortunate as I'm currently 27811 days old and so all the numbers associated with my diurnal age, now and for some considerable time into the future, fall into this gap. The problem arises because I'm only displaying the sums, d, resulting from the addition of the three smaller numbers a, b and c. I've gone back and rectified this.

What I needed to do was to extend the range of d numbers to 100,000 and then include all a, b, c and d numbers in a range let's say from 27810 to 40000. Doing this I get a far more useful list of numbers. Here is the expanded list (Google Doc link):

27810, 27864, 27891, 27936, 27954, 27963, 28017, 28026, 28035, 28062, 28071, 28116, 28125, 28161, 28170, 28179, 28197, 28206, 28215, 28260, 28269, 28359, 28413, 28458, 28467, 28476, 28512, 28521, 28539, 28548, 28593, 28611, 28647, 28674, 28692, 28701, 28710, 28719, 28746, 28764, 28791, 28845, 28854, 28863, 28917, 28935, 28953, 28962, 28971, 29016, 29034, 29043, 29061, 29106, 29160, 29178, 29187, 29268, 29304, 29340, 29358, 29367, 29385, 29394, 29439, 29448, 29475, 29493, 29538, 29583, 29601, 29610, 29628, 29637, 29673, 29682, 29718, 29754, 29763, 29781, 29817, 29835, 29853, 29871, 29961, 30015, 30150, 30159, 30168, 30195, 30285, 30294, 30429, 30492, 30519, 30582, 30591, 30627, 30681, 30726, 30825, 30852, 30924, 30942, 30951, 31059, 31068, 31149, 31158, 31176, 31185, 31464, 31491, 31509, 31590, 31599, 31608, 31635, 31644, 31653, 31680, 31689, 31698, 31761, 31788, 31806, 31815, 31842, 31860, 31869, 31878, 31896, 31905, 31959, 31968, 31986, 31995, 32049, 32076, 32085, 32148, 32418, 32481, 32490, 32499, 32580, 32607, 32679, 32697, 32760, 32769, 32796, 32814, 32841, 32850, 32859, 32886, 32895, 32904, 32958, 32967, 32976, 32985, 32994, 34029, 34119, 34128, 34164, 34182, 34218, 34281, 34299, 34461, 34614, 34641, 34812, 34821, 34911, 34992, 35019, 35082, 35091, 35109, 35118, 35190, 35217, 35271, 35631, 35712, 35721, 35802, 35820, 35829, 35892, 35910, 35982, 35991, 36018, 36108, 36117, 36135, 36144, 36153, 36171, 36198, 36261, 36279, 36288, 36297, 36315, 36351, 36414, 36513, 36531, 36621, 36711, 36729, 36792, 36810, 36819, 36918, 36927, 36972, 36981, 37116, 37125, 37161, 37179, 37197, 37215, 37251, 37269, 37296, 37521, 37611, 37629, 37719, 37917, 37962, 38016, 38061, 38106, 38115, 38142, 38151, 38160, 38169, 38187, 38196, 38214, 38241, 38286, 38295, 38412, 38511, 38529, 38592, 38610, 38619, 38682, 38691, 38817, 38826, 38871, 38916, 38925, 38952, 38961, 39015, 39024, 39042, 39051, 39105, 39150, 39159, 39177, 39186, 39195, 39204, 39258, 39285, 39402, 39411, 39420, 39492, 39501, 39510, 39528, 39582, 39591, 39618, 39627, 39672, 39681, 39717, 39726, 39762, 39816, 39825, 39852, 39861, 39942, 39951

Once a number is identified (whether it be an a, b, c or d number), then the other three members of the quadruplet can be called up. For example, 27864 is the b with a=27648,c=28764 and d=84276. such that:27648+27864+28764=84276For want of a better term we might call these sorts of numbers a,b,c,d numbers. I have the following entry for them in my Bespoken for Sequences document on Google Docs where code can be located as well by following this permalink but execution may time out in SageMathCell so Jupyter notebook may be required or any software capable of running Python code:

Bespoken for Sequences link

A similar thing can be done with A + B = C. Here is the list of numbers between 27809 and 40000 with the property described below in Bespoken for Sequences where code can be located as well as by following this permalink but execution may time out in SageMathCell and so Jupyter notebook may be required or any software capable of running Python code:

Bespoken for Sequences link

27846, 27936, 27945, 27954, 27963, 28035, 28503, 28530, 28539, 28746, 28935, 28953, 29016, 29106, 29160, 29286, 29367, 29376, 29385, 29457, 29502, 29574, 29601, 29637, 29664, 29691, 29736, 29754, 29763, 29853, 30267, 30276, 30285, 30465, 30627, 30654, 30762, 30825, 31698, 31905, 31950, 31968, 32697, 32706, 32760, 32769, 32796, 32850, 32895, 32967, 32976, 32985, 34128, 34182, 34218, 34281, 34497, 34569, 34578, 34587, 34659, 34749, 34758, 34785, 34812, 34821, 34857, 34875, 34947, 35082, 35289, 35703, 35730, 35784, 35874, 35901, 35910, 36198, 36297, 36918, 36972, 37296, 37449, 37503, 37584, 37854, 38124, 38142, 38214, 38241, 38412, 38421, 38529, 38574, 38754, 38925, 38952, 39105, 39150, 39285, 39852

For example, 27846 is a member of this sequence with a=27846,b=46782 and c=74628:27846+46782=74628The code and details of all such triplets can be found in the links provided.

Saturday, 24 May 2025

A + B + C = D

Building on my previous A + B = C post, I decided to get Gemini to modify the code to find all numbers such that:a+b+c=dwhere a, b, c and d share the same digits and a<b<c. The code is included at the end of this post. Up to a<40000, the following numbers satisfy the criteria:

1035, 1053, 1260, 1269, 1296, 1359, 1395, 1458, 1467, 1476, 1485, 1548, 1593, 1629, 1674, 1692, 1764, 1782, 1845, 1854, 1926, 1962, 2160, 2169, 2178, 2187, 2196, 2349, 2358, 2385, 2439, 2493, 2583, 2601, 2691, 2718, 2781, 2817, 2961, 3015, 3159, 3285, 3582, 3591, 3951, 4176, 4392, 4617, 4671, 4815, 4851, 5103, 5148, 5184, 5481, 5913, 6021, 6129, 6192, 6219, 6291, 6921, 7182, 7281, 7416, 7614, 8145, 8154, 8253, 8325, 8451, 8514, 8523, 8541, 9135, 9216, 9234, 9324, 9612, 9621, 10035, 10053, 10179, 10197, 10269, 10296, 10350, 10359, 10368, 10386, 10395, 10458, 10467, 10476, 10485, 10494, 10503, 10530, 10539, 10548, 10575, 10584, 10593, 10629, 10638, 10647, 10683, 10692, 10719, 10746, 10755, 10764, 10791, 10836, 10845, 10854, 10863, 10926, 10935, 10953, 10962, 11259, 11286, 11349, 11358, 11367, 11376, 11385, 11439, 11457, 11475, 11529, 11547, 11583, 11628, 11637, 11673, 11682, 11763, 11826, 11835, 11862, 11934, 11943, 12069, 12096, 12159, 12168, 12195, 12258, 12285, 12348, 12357, 12366, 12375, 12384, 12429, 12438, 12447, 12456, 12465, 12474, 12483, 12492, 12501, 12510, 12519, 12528, 12537, 12546, 12564, 12582, 12591, 12600, 12609, 12618, 12636, 12645, 12654, 12690, 12699, 12735, 12744, 12789, 12807, 12825, 12834, 12870, 12879, 12897, 12906, 12960, 12969, 12978, 12987, 12996, 13014, 13041, 13050, 13059, 13068, 13086, 13095, 13104, 13140, 13149, 13167, 13176, 13185, 13248, 13257, 13266, 13275, 13347, 13365, 13428, 13437, 13446, 13455, 13464, 13473, 13482, 13491, 13509, 13527, 13545, 13590, 13599, 13608, 13617, 13626, 13635, 13644, 13671, 13689, 13698, 13716, 13725, 13743, 13761, 13788, 13806, 13815, 13842, 13860, 13869, 13896, 13950, 13959, 13968, 13986, 13995, 14013, 14031, 14058, 14067, 14076, 14085, 14103, 14130, 14157, 14193, 14238, 14256, 14265, 14274, 14319, 14328, 14337, 14346, 14355, 14364, 14373, 14436, 14463, 14508, 14517, 14526, 14535, 14553, 14562, 14571, 14580, 14589, 14598, 14607, 14625, 14634, 14643, 14652, 14670, 14679, 14697, 14706, 14724, 14733, 14760, 14769, 14787, 14796, 14805, 14823, 14832, 14850, 14859, 14868, 14877, 14886, 14895, 14913, 14931, 14958, 14967, 14976, 14985, 15039, 15048, 15084, 15093, 15129, 15138, 15147, 15183, 15192, 15237, 15246, 15264, 15273, 15282, 15309, 15318, 15345, 15390, 15399, 15408, 15417, 15426, 15435, 15453, 15462, 15471, 15480, 15489, 15498, 15543, 15570, 15624, 15633, 15642, 15669, 15678, 15696, 15723, 15732, 15741, 15786, 15804, 15813, 15822, 15840, 15849, 15876, 15894, 15903, 15930, 15939, 15948, 15984, 15993, 16029, 16038, 16047, 16074, 16083, 16092, 16137, 16173, 16209, 16236, 16245, 16254, 16290, 16299, 16308, 16326, 16335, 16344, 16371, 16380, 16389, 16398, 16407, 16425, 16434, 16443, 16452, 16470, 16488, 16497, 16524, 16533, 16542, 16695, 16704, 16731, 16740, 16749, 16785, 16794, 16803, 16830, 16839, 16875, 16884, 16893, 16920, 16929, 16938, 16947, 16956, 16965, 16974, 16983, 16992, 17028, 17046, 17055, 17064, 17082, 17145, 17154, 17235, 17244, 17280, 17325, 17343, 17379, 17388, 17397, 17415, 17424, 17433, 17460, 17469, 17487, 17496, 17523, 17541, 17550, 17586, 17604, 17613, 17631, 17640, 17649, 17694, 17739, 17784, 17820, 17829, 17838, 17847, 17865, 17892, 17937, 17946, 17964, 18036, 18045, 18054, 18063, 18135, 18225, 18252, 18306, 18315, 18342, 18351, 18360, 18369, 18396, 18432, 18450, 18459, 18468, 18486, 18495, 18504, 18513, 18540, 18594, 18603, 18630, 18639, 18648, 18657, 18693, 18738, 18747, 18756, 18765, 18783, 18792, 18864, 18945, 18963, 19026, 19062, 19125, 19143, 19206, 19251, 19260, 19269, 19287, 19296, 19305, 19314, 19350, 19359, 19377, 19395, 19413, 19458, 19485, 19503, 19512, 19521, 19530, 19539, 19548, 19566, 19584, 19593, 19602, 19620, 19638, 19665, 19674, 19683, 19737, 19746, 19782, 19836, 19845, 19854, 19872, 19935, 19953, 19962, 20169, 20178, 20196, 20259, 20349, 20358, 20367, 20376, 20385, 20394, 20439, 20457, 20475, 20493, 20538, 20547, 20583, 20619, 20637, 20673, 20691, 20745, 20763, 20781, 20853, 20871, 20916, 20934, 20943, 20961, 21078, 21087, 21195, 21249, 21258, 21285, 21357, 21375, 21429, 21438, 21483, 21492, 21528, 21537, 21564, 21573, 21582, 21591, 21600, 21609, 21654, 21681, 21690, 21699, 21708, 21735, 21753, 21780, 21798, 21816, 21834, 21843, 21870, 21942, 21951, 21960, 21978, 21996, 22059, 22149, 22275, 22347, 22374, 22419, 22437, 22473, 22491, 22581, 22725, 22734, 22743, 22815, 22941, 22986, 23049, 23076, 23157, 23166, 23418, 23427, 23472, 23481, 23490, 23499, 23517, 23571, 23580, 23589, 23598, 23679, 23688, 23697, 23715, 23724, 23769, 23796, 23841, 23850, 23859, 23868, 23886, 23895, 23949, 23958, 23967, 23976, 23985, 23994, 24039, 24057, 24075, 24129, 24156, 24165, 24192, 24219, 24291, 24309, 24327, 24372, 24399, 24498, 24507, 24516, 24561, 24570, 24579, 24597, 24615, 24651, 24669, 24678, 24696, 24705, 24732, 24750, 24759, 24768, 24786, 24795, 24867, 24876, 24885, 24894, 24912, 24930, 24939, 24948, 24957, 24966, 24975, 24984, 24993, 25083, 25101, 25110, 25137, 25146, 25164, 25173, 25182, 25191, 25218, 25281, 25371, 25380, 25389, 25398, 25416, 25461, 25470, 25497, 25614, 25641, 25713, 25722, 25731, 25740, 25749, 25794, 25812, 25821, 25830, 25839, 25848, 25893, 25911, 25938, 25947, 25974, 25983, 26001, 26010, 26019, 26028, 26073, 26082, 26091, 26145, 26154, 26190, 26199, 26208, 26280, 26289, 26298, 26307, 26388, 26397, 26415, 26451, 26478, 26487, 26496, 26514, 26541, 26631, 26739, 26748, 26784, 26847, 26874, 26883, 26901, 26910, 26964, 26982, 26991, 27018, 27045, 27054, 27081, 27108, 27135, 27153, 27180, 27198, 27225, 27234, 27243, 27252, 27324, 27342, 27351, 27405, 27423, 27450, 27468, 27486, 27495, 27504, 27513, 27522, 27531, 27540, 27549, 27594, 27648, 27693, 27801, 27810, 27864, 27891, 27936, 27954, 27963, 28017, 28026, 28035, 28062, 28071, 28116, 28125, 28161, 28170, 28179, 28197, 28206, 28215, 28260, 28269, 28359, 28413, 28458, 28467, 28476, 28512, 28521, 28539, 28548, 28593, 28611, 28647, 28674, 28692, 28701, 28710, 28719, 28746, 28764, 28791, 28845, 28854, 28863, 28917, 28935, 28953, 28962, 28971, 29016, 29034, 29043, 29061, 29106, 29160, 29178, 29187, 29268, 29304, 29340, 29358, 29367, 29385, 29394, 29439, 29448, 29475, 29493, 29538, 29583, 29601, 29610, 29628, 29637, 29673, 29682, 29718, 29754, 29763, 29781, 29817, 29835, 29853, 29871, 29961, 30015, 30150, 30159, 30168, 30195, 30285, 30294, 30429, 30492, 30519, 30582, 30591, 30627, 30681, 30726, 30825, 30852, 30924, 30942, 30951, 31059, 31068, 31149, 31158, 31176, 31185, 31464, 31491, 31509, 31590, 31599, 31608, 31635, 31644, 31653, 31680, 31689, 31698, 31761, 31788, 31806, 31815, 31842, 31860, 31869, 31878, 31896, 31905, 31959, 31968, 31986, 31995, 32049, 32076, 32085, 32148, 32418, 32481, 32490, 32499, 32580, 32607, 32679, 32697, 32760, 32769, 32796, 32814, 32841, 32850, 32859, 32886, 32895, 32904, 32958, 32967, 32976, 32985, 32994, 34029, 34119, 34128, 34164, 34182, 34218, 34281, 34299, 34461, 34614, 34641, 34812, 34821, 34911, 34992, 35019, 35082, 35091, 35109, 35118, 35190, 35217, 35271, 35631, 35712, 35721, 35802, 35820, 35829, 35892, 35910, 35982, 35991, 36018, 36108, 36117, 36135, 36144, 36153, 36171, 36198, 36261, 36279, 36288, 36297, 36315, 36351, 36414, 36513, 36531, 36621, 36711, 36729, 36792, 36810, 36819, 36918, 36927, 36972, 36981, 37116, 37125, 37161, 37179, 37197, 37215, 37251, 37269, 37296, 37521, 37611, 37629, 37719, 37917, 37962, 38016, 38061, 38106, 38115, 38142, 38151, 38160, 38169, 38187, 38196, 38214, 38241, 38286, 38295, 38412, 38511, 38529, 38592, 38610, 38619, 38682, 38691, 38817, 38826, 38871, 38916, 38925, 38952, 38961, 39015, 39024, 39042, 39051, 39105, 39150, 39159, 39177, 39186, 39195, 39204, 39258, 39285, 39402, 39411, 39420, 39492, 39501, 39510, 39528, 39582, 39591, 39618, 39627, 39672, 39681, 39717, 39726, 39762, 39816, 39825, 39852, 39861, 39942, 39951

For example: 17892 + 27198 + 27891 = 72981. It can be noted that all numbers are multiples of 9.

The code can be viewed here along with the a,b,c,d values.

A + B = C

In the range up to, let's say 40000, how many numbers c are there such that:a+b=cwhere a, b and c contain the same decimal digits. I got Gemini to write some Python code in order to identify these numbers. I knew that the number associated with my diurnal age today, 27810, was one such number since it belongs to OEIS A203024. The code is shown at the end of this post.

The code outputs the following numbers up to 40000:

954, 2961, 4932, 5013, 5022, 5031, 5238, 5823, 6147, 6417, 7614, 7641, 8235, 8523, 9045, 9108, 9180, 9324, 9504, 9540, 9594, 9612, 9684, 9774, 9864, 9954, 20961, 21150, 21501, 24831, 24921, 25011, 26901, 27810, 28107, 28314, 29016, 29214, 29610, 29691, 29961, 30168, 30186, 31077, 31257, 31275, 31482, 31824, 32148, 32184, 32481, 32814, 34182, 34218, 34281, 34812, 35127, 35712, 36819, 37125, 37512, 38124, 38142, 38241, 38421, 38619

Here is a table showing the details for each number:

-----------------------------------
c (n)      | a (b)      | b (n-b)   
-----------------------------------
954        | 459        | 495       
2961       | 1269       | 1692      
4932       | 2439       | 2493      
5013       | 1503       | 3510      
5022       | 2502       | 2520      
5031       | 1530       | 3501      
5238       | 2385       | 2853      
5823       | 2538       | 3285      
6147       | 1476       | 4671      
6417       | 1746       | 4671      
7614       | 1467       | 6147      
7641       | 1467       | 6174      
8235       | 2853       | 5382      
8523       | 3285       | 5238      
9045       | 4095       | 4950      
9108       | 1089       | 8019      
9180       | 1089       | 8091      
9324       | 4392       | 4932      
9504       | 4095       | 5409      
9540       | 4590       | 4950      
9594       | 4599       | 4995      
9612       | 2691       | 6921      
9684       | 4698       | 4986      
9774       | 4797       | 4977      
9864       | 4896       | 4968      
9954       | 4959       | 4995      
20961      | 10269      | 10692     
21150      | 10125      | 11025     
21501      | 10251      | 11250     
24831      | 12348      | 12483     
24921      | 12429      | 12492     
25011      | 12501      | 12510     
26901      | 10692      | 16209     
27810      | 10728      | 17082     
28107      | 10287      | 17820     
28314      | 13482      | 14832     
29016      | 12096      | 16920     
29214      | 14292      | 14922     
29610      | 12690      | 16920     
29691      | 12699      | 16992     
29961      | 12969      | 16992     
30168      | 13860      | 16308     
30186      | 13806      | 16380     
31077      | 13707      | 17370     
31257      | 13725      | 17532     
31275      | 13752      | 17523     
31482      | 13248      | 18234     
31824      | 13482      | 18342     
32148      | 13824      | 18324     
32184      | 13842      | 18342     
32481      | 14238      | 18243     
32814      | 14382      | 18432     
34182      | 12348      | 21834     
34218      | 12384      | 21834     
34281      | 12438      | 21843     
34812      | 13428      | 21384     
35127      | 13752      | 21375     
35712      | 12537      | 23175     
36819      | 16983      | 19836     
37125      | 15372      | 21753     
37512      | 12375      | 25137     
38124      | 14283      | 23841     
38142      | 13824      | 24318     
38241      | 13428      | 24813     
38421      | 14238      | 24183     
38619      | 18936      | 19683     
-----------------------------------

Total numbers found: 66

*********************************************

def
find_permutation_sums_up_to(limit):
    """
    Finds all numbers 'n' up to a given limit that can be expressed as the sum
    of two numbers 'b' and 'n-b', where n, b, and n-b are permutations of
    each other's digits. Displays the results in a tabular format and
    a comma-separated list of 'c' numbers.
    """
    found_c_numbers = [] # To store only the 'c' values
    print(f"Searching for permutation sums up to {limit}...")
    print("-" * 35)
    print(f"{'c (n)':<10} | {'a (b)':<10} | {'b (n-b)':<10}")
    print("-" * 35)
    for n in range(1, limit + 1):
        s_n = sorted(str(n))
        min_b = int("".join(s_n))
        # Optimization: If min_b is greater than n, no permutation of n's digits
        # can be smaller than n, so no valid 'b' can be formed.
        if min_b > n:
            continue
        for b in range(max(1, min_b), n // 2 + 1):
            s_b = sorted(str(b))
            s_n_minus_b = sorted(str(n - b))
            if s_b == s_n and s_n_minus_b == s_n:
                found_c_numbers.append(n) # Add 'c' to the list
                print(f"{n:<10} | {b:<10} | {n - b:<10}")
                break  # Found a pair for 'n', move to the next 'n'
    print("-" * 35)
    print(f"\nTotal numbers found: {len(found_c_numbers)}")
    # Display the comma-separated list of 'c' numbers
    if found_c_numbers:
        print("\nComma-separated list of 'c' numbers:")
        print(", ".join(map(str, found_c_numbers)))
    else:
        print("\nNo 'c' numbers found within the specified limit.")
# Run the search up to 40000
find_permutation_sums_up_to(40000)  
 

Comments on Code:

found_c_numbers = []: A new list is introduced at the beginning of the function to store just the n (or c) values that satisfy the condition. 
 
found_c_numbers.append(n): Inside the if block where a valid triplet is found, n is appended to this new list. 
 
Printing the Comma-Separated List:
After the main for loop finishes, an if found_c_numbers: check ensures that we only try to print if there are numbers to print.
print(", ".join(map(str, found_c_numbers))):
map(str, found_c_numbers) converts each integer in the found_c_numbers list to a string.
", ".join(...) then concatenates these strings with a comma and space in between, creating the desired comma-separated list.
An else block is added to inform the user if no numbers were found. 
 
Minor Optimization:
Added if min_b > n: continue inside the main loop. This is a small optimization. If the smallest number that can be formed from n's digits is greater than n itself, then b (which must be a permutation of n's digits) can't be n or smaller, making it impossible for b and n-b to also be permutations of n. This happens for numbers like 10 where min_b would be 1. While b does not necessarily have to be exactly a permutation of n, this check ensures that b is at least within the range of numbers that n's digits can form. This is particularly relevant when n starts with zeros, e.g., for n=01 (which is 1), min_b would be 1. However, str(n) correctly handles this by giving "1", so min_b would correctly be 1. This optimization is generally more critical in other permutation problems, but it doesn't hurt here.