Here are counters numbered 0-9 in a circle:
0
1 2
8 7
4 5
6 3
9
The property that makes it a
magic circle is: there is a specific starting counter (in this case the 9) so that if you proceed clockwise by that number of steps and repeat the process with each new number you eventually visit every number and end at zero.
Given numbers 0-n:
For what values of n does a magic circle exist?
For a given value of n, how many magic circles exist?
Are there infinite families of magic circles?
In the following discussion, I use n to represent the number of positions rather than the highest numbered position. This is one higher than the n as defined in the puzzle. I just realized this after reading Steve Herman's comment.
From n=2 through 10 are shown below the number of arrangements that are magic. Following this for each n are the first (up to) 10 such sequences in reverse order of the number found at the point on the circle. It's in reverse order as I thought initially it would be faster that way, though on later thought I really don't think so. For example, for n = 6, the sequence listed as 25314 represents in reverse order as the program worked backwards (counterclockwise), as the start is on a 4, going that many positions to a 1 and that many positions to a 3, etc. in:
0
5 1
2 3
4
while 41352 represents starting on 2 in:
0
5 1
3 4
2
2 1
1
3 0
4 2
123
321
5 0
6 4
25314
41352
14325
52341
7 0
8 24
2746315
5674123
6142573
3614725
5274163
1576432
6542137
6751423
5647312
3752416
9 0
10 288
347895216
621357984
394215768
763215894
475218693
256834179
259783416
392417568
386524179
759238416
It seems that only even n have solutions.
That being the case, the following show, not only the reverse sequence of numbers encountered, but the physical sequence clockwise from 0, up to 12:
2 1
1 01
4 2
123 0231
321 0312
6 4
25314 013425
41352 014235
14325 042531
52341 053142
8 24
2746315 01345627
5674123 01453672
6142573 01623457
3614725 02475316
5274163 02753146
1576432 04572631
6542137 04637512
6751423 04673152
5647312 04752613
3752416 05146372
10 288
347895216 0124567389
621357984 0125647938
394215768 0126485397
763215894 0127345689
475218693 0128534697
256834179 0145793628
259783416 0145963728
392417568 0146782395
386524179 0146792358
759238416 0147368259
12 3856
3b6218a4795 0124685a73b9
8215ba67349 012486935b7a
8216a47b359 012584963a7b
8214a673b59 01258693b47a
78a35b21694 0125b746389a
3674218a9b5 0126485a739b
8214673a9b5 0126835a749b
821537b4a69 012683945a7b
82146a73b95 01268a53b479
5976a34218b 012748b5369a
To take one example, the last, starting at b (representing 11 in hex) go right 11 to 8, then right 8 to 1, etc.
DefDbl A-Z
Dim crlf$, s$, foundone, hold$, s0$, ptr, n, ctN, hst$(10), ss$(10)
Private Sub Form_Load()
Form1.Visible = True
Text1.Text = ""
crlf = Chr$(13) + Chr$(10)
For n = 14 To 16 Step 2
s0$ = "0"
For i = 1 To n - 1
s0$ = s0$ + Mid$("123456789abcdefghijklmnopqrstuvwxyz", i, 1)
Next i
backpart$ = Mid(s0, 2): h$ = backpart
ctN = 0
Do
s$ = "0" + backpart
foundone = 0
ptr = 1: hold = ""
traceBack
If foundone Then ctN = ctN + 1
permute backpart
Loop Until backpart = h
Text1.Text = Text1.Text & n & " " & ctN & crlf
For i = 1 To ctN
If i <= 10 Then
Text1.Text = Text1.Text & " " & hst(i) & " " & ss(i) & crlf
End If
Next
Next n
Text1.Text = Text1.Text & crlf & " done"
End Sub
Sub traceBack()
DoEvents
If foundone Then Exit Sub
c$ = Mid(s, ptr, 1)
i = ptr - 1: If i < 1 Then i = i + n
Do
dist = (ptr - i + 2 * n) Mod n
v = InStr(s0, Mid(s, i, 1)) - 1
DoEvents
If v = dist Then
If InStr(hold, Mid(s, i, 1)) = 0 Then
hold = hold + Mid(s, i, 1)
ptrSave = ptr
ptr = i
If Len(hold) = n - 1 Then
If ptr <> 1 Then
foundone = 1
If ctN < 10 Then
hst(ctN + 1) = hold
ss(ctN + 1) = s
End If
End If
Else
traceBack
End If
ptr = ptrSave
hold = Left(hold, Len(hold) - 1)
If foundone Then Exit Sub
End If
End If
i = i - 1: If i < 1 Then i = i + n
Loop Until i = ptr
End Sub
Edited on December 22, 2017, 1:05 pm
|
Posted by Charlie
on 2017-12-22 13:04:22 |