Showing posts with label grid. Show all posts
Showing posts with label grid. Show all posts

Monday, 2 November 2026

Binary Display

I noticed that Numbers Aplenty had the display shown in Figure 1 as part of its output for the number associated with my diurnal age today (28337) with the comment that "when arranged in a rectangular grid, its binary digits exhibit some kind of symmetry". The binary digits are 110111010110001 and there are 15 of them so they can be arranged in a 5 x 3 grid.


Figure 1

I quite liked this output and decided to incorporate it into the program for my daily number analysis. The output is as shown in Figure 2.


Figure 2

Every day, from this day forwards, there will be a similar display and I can decide whether there is anything of interest regarding the display, symmetrical or otherwise. Figure 3 shows the results for 27334 where there is also lateral symmetry.


Figure 3

The range of numbers for which there are 15 binary digits is 16,384 to 32,767 corresponding to \(2^{14}\) and \(2^{15}-1\). Prior to 16384, there is a range of numbers with 14 binary digits that can also be arranged in a rectangular grid. This range is from 8192 to 16383 corresponding to \(2^{13}\) and \(2^{14}-1\). Figure 4 shows the display for 16382:


Figure 4

Above 32767, we enter the realm of 16 binary digits and no grid will be displayed. The output for 32768 would be:

Integer : 32768
Binary  : 1000000000000000
Length  : 16 binary digits

Result  : Bit length 16 (factorization: 2^4) is NOT a biprime. 

No grid generated.

Of course, a 4 x 4 or 8 x 2 grid could be generated with a tweak of the algorithm but I'll consider that as I approach 32768 by which point I'll be 89 years old.

Sunday, 24 May 2026

The 5 x 5 Grid Game

The 5x5 Grid Game

Here is a game that I conceived and that Gemini helped me refine and then finally implement for a single player. I got the idea for creating this game while reading "Around the World in 80 Games" by Marcus du Sautoy. He makes no mention of the game I conceived of but the book served as inspiration. It's remarkable how easily Gemini created the game once it was given clear instructions as to what I wanted.

How to Play: The 5x5 Grid Game

Welcome to the grid! This is a game of probability, spatial strategy, and risk management. Your goal is to fill a 5x5 grid with numbers to create specific mathematical sequences across the board.

The Basics

  • The Grid: You have an empty 5x5 grid. By the end of the game, every square will contain a single digit (0-9).
  • The Dice: Each turn, two six-sided dice are rolled. The sum of the dice determines the digit you must play:
    • Sums 2 through 9 equal their exact face value.
    • A sum of 10 equals 0.
    • A sum of 11 equals 1.
    • A sum of 12 is a Wildcard! You may choose any digit from 0 to 9.
  • Placement: You can place your digit in any empty square. Once it is placed, it is locked in forever. Plan carefully!

Scoring Your Grid

When the grid is full (after 25 rolls), the game evaluates 12 different lines for points:

  • 5 Horizontal Rows (read left to right)
  • 5 Vertical Columns (read top to bottom)
  • 2 Diagonals (top-left to bottom-right, and top-right to bottom-left)

The Points System

Tier Points Number Types
Tier 1: Base 1 Xenodrome, Non-prime digits only, Balanced number, Cyclops number
Tier 2: Uncommon 3 Balance of prime/non-prime, Balance of odd/even, Mountain number, Odd digits only
Tier 3: Rare 5 Even digits only, Nailpdrome, Plaindrome, Palindrome
Tier 4: Extreme 15 Prime digits only, Katadrome, Metadrome
Tier 5: Jackpot 30 Repdigits, Fibonacci

Glossary of Number Types

  • Xenodrome: No digits are repeated (e.g., 17384).
  • Plaindrome: Digits ascend, repeats allowed (e.g., 23447).
  • Metadrome: Digits strictly ascend, no repeats (e.g., 13468).
  • Nailpdrome: Digits descend, repeats allowed (e.g., 97752).
  • Katadrome: Digits strictly descend, no repeats (e.g., 86421).
  • Palindrome: Reads the same forwards and backwards (e.g., 42724).
  • Repdigits: All 5 digits are identical (e.g., 66666).
  • Cyclops number: Contains exactly one "0", and it is sitting dead center.
  • Mountain number: Digits strictly ascend to a peak, then strictly descend.
  • Prime digits only: Only 2, 3, 5, or 7.
  • Non-prime digits only: Only 0, 1, 4, 6, 8, or 9.
  • Even digits only: Only 0, 2, 4, 6, or 8.
  • Odd digits only: Only 1, 3, 5, 7, or 9.
  • Balance prime/non-prime: The sum of the prime digits equals the sum of the non-prime digits.
  • Balance odd/even: The sum of the odd digits equals the sum of the even digits.
  • Balanced number: The sum of the first two digits equals the sum of the last two digits.
  • Fibonacci: The 1st & 2nd digits add up to the 3rd. The 2nd & 3rd add to the 4th. The 3rd & 4th add to the 5th.

Play The Game

Rolls Remaining: 25

Press 'Roll Dice' to begin.

Final Score Report

Total Score: 0 Points

The Odds: Know Your Probabilities

Because every square on the grid accepts any number (including zeros), the math is completely uniform across the board. The game is driven by the bell curve of two six-sided dice. Here is the exact chance of rolling each total:

Dice Total Probability
22.78%
35.56%
48.33%
511.11%
613.89%
7 (Most Common)16.67%
813.89%
911.11%
10 (Digit 0)8.33%
11 (Digit 1)5.56%
12 (Wildcard)2.78%

The True Digit Probabilities

Because rolling a 12 lets you pick any number, the Wildcard effectively adds a tiny fraction of probability (0.28%) to every single digit. When you combine the natural dice rolls with the strategic use of Wildcards, here is how likely you are to actually secure each digit on the grid:

Grid Digit True Probability Sourced From
23.06%Roll 2 + Wildcard
1, 35.83%Roll 11 or 3 + Wildcard
0, 48.61%Roll 10 or 4 + Wildcard
5, 911.39%Roll 5 or 9 + Wildcard
6, 814.17%Roll 6 or 8 + Wildcard
716.94%Roll 7 + Wildcard

Strategy Tip: Building lines that require 2s, 1s, or 3s is incredibly risky without relying heavily on Wildcards. High-probability digits like 6, 7, and 8 will quickly flood your board.

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

Thursday, 15 February 2024

Diurnal Age Meets Conway's Game Of Life

 I've written about Conway's Game of Life in two recent posts:

I've been playing around with an app called "Life" on my iPhone that allows the game to be run but I prefer on browser-based app that I can access from my laptop. To that end, I've been playing around with one of three websites recommended by Gemini:
This website utilizes the popular "Golly" simulation software, offering advanced features like pattern libraries, scripting, and different grid geometries. You can save and export your simulations in various formats.
This website allows you to draw patterns directly on the grid with an intuitive interface. While it lacks advanced features, it's great for quick visualizations and sharing creations.

So in this post, I'm looking at the first of the recommendations and playing around with a new idea. I want to investigate how the number associated with my diurnal age behaves under the Game of Life rules. The number for today, 27346, is shown in Figure 1. All the digits from 0 to 9 can be created using a 3 x 5 pixel grid, the smallest possible size.


Figure 1

The rules lead, after 125 steps, to the image shown in Figure 2:


Figure 2

What would be interesting to keep track of are the number of steps required to reach a stable state. It's clear that the stable states arising from numbers are not unique. For example 16161 will end up the same as 19191 if we don't regard mirror images, rotations and reflections as different. However, most numbers should result in stable states that are different from one another. I can attach images of these stable states to my Airtable database. 

I'll explore the other two Gemini recommendations later. Any particularly interesting stable states or record number of steps arising from these diurnal age investigations can be the subject of future posts. In the case of 27346, we can say that the stable state consists of five blocks (the simplest still life) and one hive or beehive (the second most common still life).

 

This ongoing, daily exercise is a great way to deepen ones understanding of a topic. It was only through my adherence to the investigation of the number associated with my diurnal age that I widened and deepened my understanding of number theory. It's a great maxim: once a day but everyday and can be and should be applied to more aspects of my daily life.

Thursday, 2 March 2023

Hamiltonian Paths Revisited

On the 6th February 2021, I posted about Hamiltonian Paths and Knight's Tours. That was over two years ago now but today I have the opportunity to revisit the topic of Hamiltonian paths because the number associated with my diurnal age, 26996, is a member of OEIS A003778:


 A003778

Number of Hamiltonian paths in \(P_5 \times P_n \).               



In the case of 26996, \(n=6\).  Figure 1 shows such a \(5 \times 6 \) grid.


Figure 1

A Hamiltonian path is one that passes through every vertex exactly once. One example of such a path is shown in Figure 2. Note that in this 2D grid connections between vertices or nodes are made up-down and left-right but not diagonally.


Figure 2

In the case of a \(5 \times 6\) grid, there are 26996 such paths that can be drawn. The number of paths increases rapidly as the number of points increases. Here are the initial values:
  • \(5 \times 1 \rightarrow 1\)
  • \(5 \times 2 \rightarrow 22\)
  • \(5 \times 3 \rightarrow 132\)
  • \(5 \times 4 \rightarrow 1006\)
  • \(5 \times 5 \rightarrow  4324\)
  • \(5 \times 6 \rightarrow 26996\)
  • \(5 \times 7 \rightarrow  109722\)
  • \(5 \times 8 \rightarrow 602804\)
  • \(5 \times 9 \rightarrow 2434670\) 
  • \(5 \times 10 \rightarrow 12287118\)
Here is a permalink to some Python code that will plot a Hamiltonian path through a grid of specified size. Figure 3 shows the output in the case of a \(5 \times 6\) grid:

[(0, 0), (0, 1), (0, 2), (0, 3), (0, 4), (0, 5), (1, 5), (1, 4), (1, 3), (1, 2), (1, 1), (1, 0), (2, 0), (2, 1), (2, 2), (2, 3), (2, 4), (2, 5), (3, 5), (3, 4), (3, 3), (3, 2), (3, 1), (3, 0), (4, 0), (4, 1), (4, 2), (4, 3), (4, 4), (4, 5)]


Figure 3

This YouTube video does a good job of explaining in simple terms the difference between a Hamiltonian path and an Euler path. For the latter, the path must traverse every edge exactly once whereas in the former it is every vertex that must be traversed.

There is a 36-term linear recurrence mentioned in the OEIS A003778 comments which is the closest thing to a formula that seems to be available for calculating the number of possible paths. Hamiltonian paths and cycles are intimately connected with the travelling salesman problem as this site explains:
Travelling Salesman Problem (TSP): 

Given a set of cities and the distance between every pair of cities, the problem is to find the shortest possible route that visits every city exactly once and returns to the starting point. Note the difference between Hamiltonian Cycle and TSP. The Hamiltonian cycle problem is to find if there exists a tour that visits every city exactly once. Here we know that Hamiltonian Tour exists (because the graph is complete) and in fact, many such tours exist, the problem is to find a minimum weight Hamiltonian Cycle. 

Figure 4

For example, consider the graph shown in the Figure 4 on the right side. A TSP tour in the graph is 1-2-4-3-1. The cost of the tour is 10+25+30+15 which is 80. The problem is a famous NP-hard problem. There is no polynomial-time know solution for this problem. 

The site goes to provide programming solutions to this particular instance of the TSP but the Python3 solution doesn't work. However, the minimum cost Hamiltonian tour is  80 and 1-2-4-3-1 is one solution. This YouTube video offers a useful tutorial on how to draw graphs, such as the one shown in Figure 3, using SageMath.

I discovered an interesting site called Graph Online that allows you to create graphs and find Hamiltonian and Eulerian paths and cycles as well as Adjacency and Incidence Matrices. Figure 5 shows the Hamiltonian path that it came up with for the graph that I drew. No Hamiltonian cycle is possible.

Figure 5

Figure 6 shows a Eulerian path. No Eulerian cycle is possible. The site will display and analyse many other types of graphs. I've just focused on two here.


Figure 6