Showing posts with label formulae. Show all posts
Showing posts with label formulae. Show all posts

Thursday, 6 November 2025

Passcodes and Repeated Digits

The content in this post is taken from this video on the YouTube channel MindYourDecisions. Figure 1 shows if the digits of a four digit code are known, there are 24 possibilites of the code contains four distinct digits but 36 possibilities if the code contains only three digits (with one digit repeated).


Figure 1

If no digits are repeated, then there are:$$4! = 4 \times 3 \times 2 \times 1 =24 \text{ possibilities}$$However if one digit is repeated then we have:$$ \frac{4!}{2!} \times 3 = 36 \text{ possibilities}$$What happens with a six digit passcode when we know the digits but not the order. If six digits are used, then we have:$$6! = 6 \times 5 \times 4 \times 3 \times 2 \times 1  = 720 \text{ possibilities}$$However, if one digit is repeated then we have:$$ \frac{6!}{2!} \times 5 =1800 \text{ possibilities: see Figure 2}$$

Figure 2

The formulae in general for distinct digits versus one repeated digit are:$$ n! \leftarrow \text{ versus } \rightarrow \frac{(n-1) \times n!}{2}$$Once we have \(n \geq 4\) then \( (n-1)/2 \) is greater than 1 and so the single repeated digit passcode will always yield more possibilities than the distinct digits. What about repeating more than one digit? 

Figure 3 shows the situation for six digit passcodes where it can be seen that one repeated digit yields the most possibilities:


Figure 3

However, for a seven digit posscode, using five distinct digits (with two digits repeated) yields the most possibilities. See Figure 4.


Figure 4

The video referenced earlier concludes with a mention of the general case and a rather formidable formula that I won't go into here.

Friday, 26 April 2024

Perimeter Magic Polygons

My previous post was titled Anti-Magic Squares Revisited in which I mentioned heterosquares. Only today however, I came across the concept of a perimeter magic square that is an example of a perimeter magic polygon or PMP to use an acronym. The definition is:

A PMP is defined to be a regular polygon with the consecutive positive integers from 1 to N placed along the perimeter in such a way that the sums of the integers on each side are constant. The order of a polygon refers to the number of integers along each side. The examples in Figures 1, 2 and 3 show a 4th-order triangle, and a 3rd-order square and pentagon. The magic constants are given inside the figures. Source.

Let's look at some perimeter magic triangles to begin with. To quote from Wikipedia:
A magic triangle or perimeter magic triangle is an arrangement of the integers from 1 to \(n\) on the sides of a triangle with the same number of integers on each side, called the order of the triangle, so that the sum of integers on each side is a constant, the magic sum of the triangle. Unlike magic squares, there are different magic sums for magic triangles of the same order. Any magic triangle has a complementary triangle obtained by replacing each integer \(x\) in the triangle with \(1 + n − x\). See Figure 4.


Figure 4

The author of this paper comes up to two sets of formula in which \(C\) is the magic constant,  \(n\) is the order of the polygon and \(k\) is the number of sides. Figures 5 and 6 show these.

Figure 5 shows the formulae for the case of \(n\) even or both \(n\) and \(k\) odd.


Figure 5

Figure 6 shows the formulae for the case of \(n\) is odd and \(k\) is even.


Figure 6

To quote from the article:
With these formulas one can now begin to construct PMPs of any order and number of sides. One word of caution is still in order. There are times when a solution is not possible for certain values of C. The formulas only serve to indicate where solutions may be found, and that there is no need to look elsewhere. However, luck is still with the solver. Based on this author's experience, there are only two cases where solutions cannot be made with values obtained from the formulas. These are 4th-order triangles with \(C \) = 18 and 22, and 3rd-order pentagons with \( C \) = 15 and 18.

By controlling certain of the variables, one can discover some interesting patterns that permit the rapid construction of special PMPs. For example, for 3rd-order PMPs with an odd number of sides, it can be proved that a solution s always possible for the minimum \(C \). And it can be further demonstrated (to the amazement of your friends) that you can produce the solution just as rapidly as it takes to write the \(N\) integers. Rather than present the proof here, two examples will be given, and you can easily note the pattern for yourself.

Figure 7 shows the two examples. 14 is the minimum value of \(C\) for \(n\) = 3 and \(k\) = 5. 19 is the minimum value for \(n\) = 3 and \(k\) = 7.


Figure 7

The pattern in easily perceived once you look at the numbers closely. The article goes further into how to create various PMPs and reference should be made to that for further examples. 

I stumbled upon this topic by way of the number associated with my diurnal age today, 27417. This number is a member of OEIS A135503 for the case where \(n\) = 38.


 A135503

\( \text{a} (n) = \dfrac{n \cdot (n^2 - 1)}{2} \)



The initial members of the sequence are:

0, 0, 3, 12, 30, 60, 105, 168, 252, 360, 495, 660, 858, 1092, 1365, 1680, 2040, 2448, 2907, 3420, 3990, 4620, 5313, 6072, 6900, 7800, 8775, 9828, 10962, 12180, 13485, 14880, 16368, 17952, 19635, 21420, 23310, 25308, 27417, 29640, 31980, 34440

The OEIS comments state that for \(n\) > 2, a(\(n\)) is the maximum value of the magic constant in a perimeter-magic \(n\)-gon of order \(n \). For the case of \(n\) = 38, \(n\) is even and so the formula in Figure 5 applies. Substituting in \(n\) = 38 and \(k\) = 38 does indeed give the maximum value of the magic constant as 27417.