Constructing Concentric Rings of Numbers#

In this article, we will explore a method for constructing concentric rings of numbers, where a given number is placed at the center, and we decrease the numbers as we create rings around it until we reach one.

Concept Overview#

Let’s say our argument is 5. In our construction, we will place 5 in the middle, followed by 4, then 3, and so on down to 1. The result will resemble a large concentric arrangement:

4 4 4 4 4
4 3 3 3 4
4 3 5 3 4
4 3 3 3 4
4 4 4 4 4

To create this structure, we can define a monadic function in APL that takes an integer scalar as an argument. Here’s an example of how we define such a function:

F  { (∘.⊢⌊(0¯1+2×)) }

Generating the Sequence#

To create this concentric ring structure, we first need to generate the sequence of numbers:

  1. Start with the center number as the argument (e.g., 5).

  2. Create rings around it, decreasing the values as we move outward (i.e., 4, 3, 2, 1).

  3. Form the sequence and then reverse it to create the outer layers.

In APL, we can generate a sequence using:

5

This will yield the sequence:

1 2 3 4 5

As we reverse the sequence, we must ensure that we avoid duplicating the middle element. This can be accomplished by dropping the first element of the reversed sequence using:

(⊢,1↓⌽) 5

This output will be:

1 2 3 4 5 4 3 2 1

Expanding to a Matrix#

Next, we need to expand this sequence into a full matrix format. One way to visualize it is to think of it as a multiplication table. For example, we can create an outer product of our sequence:

(⊢,1↓⌽) 5

This will create:

1 2 3 4 5 5 4 3 2 1

However, we don’t need a traditional multiplication table. Instead, to visualize the minimum values from the respective rows and columns, we can apply the following function:

(∘.×⊢,1↓⌽) 5

This gives us:

1  2  3  4  5  4  3  2 1
2  4  6  8 10  8  6  4 2
3  6  9 12 15 12  9  6 3
4  8 12 16 20 16 12  8 4
5 10 15 20 25 20 15 10 5
4  8 12 16 20 16 12  8 4
3  6  9 12 15 12  9  6 3
2  4  6  8 10  8  6  4 2
1  2  3  4  5  4  3  2 1

Now, applying a final minimum function leads us to the correct concentric rings structure. Using APL:

(∘.⊢,1↓⌽) 5

Results in:

1 1 1 1 1 1 1 1 1
1 2 2 2 2 2 2 2 1
1 2 3 3 3 3 3 2 1
1 2 3 4 4 4 3 2 1
1 2 3 4 5 4 3 2 1
1 2 3 4 4 4 3 2 1
1 2 3 3 3 3 3 2 1
1 2 2 2 2 2 2 2 1
1 1 1 1 1 1 1 1 1

Minimum Function#

To achieve the desired form, we implement a minimum function. The minimum function is represented in APL as follows:

F {∘.⊢,1↓⌽}  

By applying this minimum function across our rows and columns, we ensure that the final output reflects the correct rings.

Final Implementation#

This process can be encapsulated in a function F, where we can apply F to our sequence. This will yield the concentric ring pattern we desire:

F 5

This returns the successful construction of concentric rings:

1 1 1 1 1 1 1 1 1
1 2 2 2 2 2 2 2 1
1 2 3 3 3 3 3 2 1
1 2 3 4 4 4 3 2 1
1 2 3 4 5 4 3 2 1
1 2 3 4 4 4 3 2 1
1 2 3 3 3 3 3 2 1
1 2 2 2 2 2 2 2 1
1 1 1 1 1 1 1 1 1

Thank you for reading! We hope this guide helps you understand how to construct concentric rings of numbers effectively.