Railway circuit: Difference between revisions
m
→{{header|Wren}}: Changed to Wren S/H
m (→{{header|Julia}}: typo) |
m (→{{header|Wren}}: Changed to Wren S/H) |
||
(19 intermediate revisions by 5 users not shown) | |||
Line 41:
Count the number of circuits '''Cn,m''' with '''n''' same as above and '''m''' = 2 to 8
<br><br>
=={{header|11l}}==
{{trans|Kotlin}}
<syntaxhighlight lang="11l">
-V
RIGHT = 1
LEFT = -1
STRAIGHT = 0
F normalize(tracks)
V a = tracks.map(tr -> ‘abc’[tr + 1]).join(‘’)
V norm = a
L 0 .< tracks.len
I a < norm
norm = a
a = a[1..]‘’a[0]
R norm
F full_circle_straight(tracks, nStraight)
I nStraight == 0
R 1B
I sum(tracks.map(i -> Int(i == :STRAIGHT))) != nStraight
R 0B
V straight = [0] * 12
V i = 0
V idx = 0
L i < tracks.len & idx >= 0
I tracks[i] == :STRAIGHT
straight[idx % 12]++
idx += tracks[i]
i++
R !(any((0.<6).map(i -> @straight[i] != @straight[i + 6]))
& any((0.<8).map(i -> @straight[i] != @straight[i + 4])))
F full_circle_right(tracks)
I sum(tracks) * 30 % 360 != 0
R 0B
V rTurns = [0] * 12
V i = 0
V idx = 0
L i < tracks.len & idx >= 0
I tracks[i] == :RIGHT
rTurns[idx % 12]++
idx += tracks[i]
i++
R !(any((0.<6).map(i -> @rTurns[i] != @rTurns[i + 6]))
& any((0.<8).map(i -> @rTurns[i] != @rTurns[i + 4])))
T PermutationsGen
[Int] indices, choices
carry = 0
F (numPositions, choices)
.indices = [0] * numPositions
.choices = copy(choices)
F next()
.carry = 1
V i = 1
L i < .indices.len & .carry > 0
.indices[i] += .carry
.carry = 0
I .indices[i] == .choices.len
.carry = 1
.indices[i] = 0
i++
R .indices.map(i -> @.choices[i])
F has_next()
R .carry != 1
F get_permutations_gen(nCurved, nStraight)
assert((nCurved + nStraight - 12) % 4 == 0, ‘input must be 12 + k * 4’)
V trackTypes = [:RIGHT, :LEFT]
I nStraight != 0
I nCurved == 12
trackTypes = [:RIGHT, :STRAIGHT]
E
trackTypes = [:RIGHT, :LEFT, :STRAIGHT]
R PermutationsGen(nCurved + nStraight, trackTypes)
F report(sol, numC, numS)
print("\n#. solution(s) for C#.,#. ".format(sol.len, numC, numS))
I numC <= 20
L(tracks) sorted(sol.values())
L(track) tracks
print(‘#2 ’.format(track), end' ‘’)
print()
F circuits(nCurved, nStraight)
[String = [Int]] solutions
V gen = get_permutations_gen(nCurved, nStraight)
L gen.has_next()
V tracks = gen.next()
I !full_circle_straight(tracks, nStraight)
L.continue
I !full_circle_right(tracks)
L.continue
solutions[normalize(tracks)] = tracks
report(solutions, nCurved, nStraight)
L(n) (12..24).step(4)
circuits(n, 0)
circuits(12, 4)
</syntaxhighlight>
{{out}}
<pre>
1 solution(s) for C12,0
1 1 1 1 1 1 1 1 1 1 1 1
1 solution(s) for C16,0
1 1 1 1 1 1 1 -1 1 1 1 1 1 1 1 -1
6 solution(s) for C20,0
1 1 1 1 -1 1 1 1 1 -1 1 1 1 1 -1 1 1 1 1 -1
1 1 1 1 1 -1 1 1 1 -1 1 1 1 1 1 -1 1 1 1 -1
1 1 1 1 1 1 -1 1 1 -1 1 1 1 1 1 1 -1 1 1 -1
1 1 1 1 1 1 1 -1 1 -1 1 1 1 1 1 1 1 -1 1 -1
1 1 1 1 1 1 1 -1 1 1 -1 1 1 1 1 1 1 1 -1 -1
1 1 1 1 1 1 1 1 -1 -1 1 1 1 1 1 1 1 1 -1 -1
40 solution(s) for C24,0
4 solution(s) for C12,4
1 1 1 0 1 1 1 0 1 1 1 0 1 1 1 0
1 1 1 1 0 1 1 0 1 1 1 1 0 1 1 0
1 1 1 1 1 0 1 0 1 1 1 1 1 0 1 0
1 1 1 1 1 1 0 0 1 1 1 1 1 1 0 0
</pre>
=={{header|EchoLisp}}==
<
;; R is turn counter in right direction
;; The nb of right turns in direction i
Line 146 ⟶ 291:
(printf "Number of circuits C%d,%d : %d" maxn straight (vector-length *circuits*)))
(when (< (vector-length *circuits*) 20) (for-each writeln *circuits*)))
</syntaxhighlight>
{{out}}
<pre>
Line 183 ⟶ 328:
=={{header|Go}}==
{{trans|Kotlin}}
<
import "fmt"
Line 382 ⟶ 527:
}
circuits(12, 4)
}</
{{out}}
Line 412 ⟶ 557:
1 1 1 0 1 1 1 0 1 1 1 0 1 1 1 0
</pre>
=={{header|J}}==
Implementation (could be further optimized0:<syntaxhighlight lang="j">NB. is circuit valid?
vrwc=: {{ */1=({:,1++/)*/\^j.1r6p1*y }}"1
NB. canonical form for circuit:
crwc=: {{ {.\:~,/(i.#y)|."0 1/(,|.)y,:-y }}"1
NB. all valid railway circuits with y 30 degree curves
rwc=: {{
r=. EMPTY
h=. -:y
sfx=. (]/.~ 2|+/"1)#:i.2^h
for_pfx. (-h){."1 #:i.2^_3+h do. p=.2|+/pfx
r=. r,~.crwc (#~ vrwc) _1^pfx,"1 p{sfx
end.
'SLR'{~~.r
}}
NB. all valid railway circuits with y 30 degree curves and x straight segments
rwcs=: {{
r=. EMPTY
h=. -:y+x
sfx=. (h#3)#:i.3^h
for_pfx. sfx do.
r=. r,~.crwc (#~ vrwc) (#~ x= 0 +/ .="1]) 0 1 _1{~pfx,"1 sfx
end.
'SLR'{~~.r
}}</syntaxhighlight>
Task examples:<syntaxhighlight lang="j"> rwc 12
LLLLLLLLLLLL
rwc 16
LLLLLLLRLLLLLLLR
rwc 20
LLLLLLLLRRLLLLLLLLRR
LLLLLLLRLLRLLLLLLLRR
LLLLLLLRLRLLLLLLLRLR
LLLLLLRLLRLLLLLLRLLR
LLLLLRLLLRLLLLLRLLLR
LLLLRLLLLRLLLLRLLLLR
#rwc 24
40
#rwc 28
293
#rwc 32
2793
4 rwcs 12
LLLLLLSSLLLLLLSS
LLLLLSLSLLLLLSLS
LLLLSLLSLLLLSLLS
LLLSLLLSLLLSLLLS</syntaxhighlight>
Symbols:
R: right (-1)
L: left ( 1)
S: straight ( 0)
=={{header|Java}}==
{{works with|Java|8}}
<
import static java.util.Arrays.stream;
Line 576 ⟶ 778:
return carry != 1;
}
}</
<pre>1 solution(s) for C12,0
1 1 1 1 1 1 1 1 1 1 1 1
Line 607 ⟶ 809:
=={{header|Julia}}==
[[File:Railway_circuit_examples.png|320px]]
<syntaxhighlight lang="julia">
#=
Exhaustive search for complete railway (railroad track) circuits. A valid circuit begins and ends at the
same point
curves or are straight track that can be placed at -90, 0, or 90 degree angles from starting points.
Line 623 ⟶ 827:
There is another factor in equivalence groups not mentioned in the task as of June 2022: __vector reversal__.
If __vector reversal__ is included, (
Furthermore, if chosen, reversal of the turns vector (not mentioned as a source of symmetry in the task)
Line 637 ⟶ 841:
Graphic displays of solutions are via a Gtk app and Cairo graphics.
=#
""" Rosetta Code task rosettacode.org/wiki/Railway_circuit. """
Line 663 ⟶ 866:
""" Determine if vector `turns` is in an equivalence group with the vector `groupmember` """
function isinequivalencegroup(turns, groupmember, reversals = false)
for i in eachindex(turns)
groupmember == circshift(turns, i - 1) && return true
Line 670 ⟶ 873:
for i in eachindex(invturns)
groupmember == circshift(invturns, i - 1) && return true
end
if reversals
revturns = reverse(turns)
for i in eachindex(revturns)
groupmember == circshift(revturns, i - 1) && return true
end
invturns = -1 .* revturns
for i in eachindex(invturns)
groupmember == circshift(invturns, i - 1) && return true
end
end
return false
Line 714 ⟶ 927:
""" Returns true if the path of turns returns to starting point, and on that return is
moving in a direction
"""
function isclosedpath(turns, straight, start = Point(0.0, 0.0))
Line 830 ⟶ 1,043:
end
# Note 4:2:36 takes a long time, for shorter runs do 4:4:24 here for i
for i = 4:2:36, rev in false:true, str in false:true
str && i > 16 && continue
@time allvalidcircuits(i; verbose = !str && i < 28, reversals = rev, straight = str, graphic = i == 24)
end
</
<pre>
For N of 4 and curved track, including reversed curves:
Found 0 unique valid circuits.
0.000907 seconds (70 allocations: 4.461 KiB)
For N of 4 and straight track, including reversed curves:
Found 1 unique valid circuits.
0.000675 seconds (209 allocations: 17.836 KiB)
For N of 4 and curved track, excluding reversed curves:
Found 0 unique valid circuits.
0.000737 seconds (68 allocations: 4.430 KiB)
For N of 4 and straight track, excluding reversed curves:
Found 1 unique valid circuits.
0.000724 seconds (218 allocations: 18.477 KiB)
For N of 6 and curved track, including reversed curves:
Found 0 unique valid circuits.
0.000748 seconds (165 allocations: 15.727 KiB)
For N of 6 and straight track, including reversed curves:
Found 1 unique valid circuits.
0.001228 seconds (1.51 k allocations: 162.398 KiB)
For N of 6 and curved track, excluding reversed curves:
Found 0 unique valid circuits.
0.000816 seconds (164 allocations: 15.430 KiB)
For N of 6 and straight track, excluding reversed curves:
Found 1 unique valid circuits.
0.001109 seconds (1.52 k allocations: 164.227 KiB)
For N of 8 and curved track, including reversed curves:
Found 0 unique valid circuits.
0.000728 seconds (548 allocations: 65.430 KiB)
For N of 8 and straight track, including reversed curves:
Found 7 unique valid circuits.
0.004763 seconds (13.64 k allocations: 1.665 MiB)
For N of 8 and curved track, excluding reversed curves:
Found 0 unique valid circuits.
0.000924 seconds (549 allocations: 65.727 KiB)
For N of 8 and straight track, excluding reversed curves:
Found 7 unique valid circuits.
0.003679 seconds (13.77 k allocations: 1.680 MiB)
For N of 10 and curved track, including reversed curves:
Found 0 unique valid circuits.
0.000959 seconds (2.08 k allocations: 289.430 KiB)
For N of 10 and straight track, including reversed curves:
Found 23 unique valid circuits.
0.044344 seconds (123.94 k allocations: 17.029 MiB, 33.72% gc time)
For N of 10 and curved track, excluding reversed curves:
Found 0 unique valid circuits.
0.001132 seconds (2.08 k allocations: 289.430 KiB)
For N of 10 and straight track, excluding reversed curves:
Found 15 unique valid circuits.
0.027965 seconds (121.00 k allocations: 16.624 MiB)
For N of 12 and curved track, including reversed curves:
[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]
Found 1 unique valid circuits.
0.004032 seconds (8.37 k allocations: 1.259 MiB)
For N of 12 and straight track, including reversed curves:
Found 141 unique valid circuits.
0.308568 seconds (1.31 M allocations: 200.564 MiB, 17.57% gc time)
For N of 12 and curved track, excluding reversed curves:
[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]
Found 1 unique valid circuits.
0.004644 seconds (8.39 k allocations: 1.262 MiB)
For N of 12 and straight track, excluding reversed curves:
Found 95 unique valid circuits.
0.235373 seconds (1.18 M allocations: 180.146 MiB, 13.06% gc time)
For N of 14 and curved track, including reversed curves:
Found 0 unique valid circuits.
0.005226 seconds (32.80 k allocations: 5.501 MiB)
For N of 14 and straight track, including reversed curves:
Found 871 unique valid circuits.
3.911026 seconds (20.58 M allocations: 3.374 GiB, 15.87% gc time)
For N of 14 and curved track, excluding reversed curves:
Found 0 unique valid circuits.
0.007905 seconds (32.80 k allocations: 5.501 MiB)
For N of 14 and straight track, excluding reversed curves:
Found 465 unique valid circuits.
2.412965 seconds (12.72 M allocations: 2.086 GiB, 14.93% gc time)
For N of 16 and curved track, including reversed curves:
[1, 1, 1, 1, 1, 1, 1, -1, 1, 1, 1, 1, 1, 1, 1, -1]
Found 1 unique valid circuits.
0.013655 seconds (131.30 k allocations: 24.013 MiB)
For N of 16 and straight track, including reversed curves:
Found 6045 unique valid circuits.
75.173632 seconds (689.14 M allocations: 123.235 GiB, 22.65% gc time)
For N of 16 and curved track, excluding reversed curves:
[1, 1, 1, 1, 1, 1, 1, -1, 1, 1, 1, 1, 1, 1, 1, -1]
Found 1 unique valid circuits.
0.015041 seconds (131.33 k allocations: 24.019 MiB)
For N of 16 and straight track, excluding reversed curves:
Found 3217 unique valid circuits.
48.776209 seconds (432.90 M allocations: 77.415 GiB, 21.55% gc time)
For N of 18 and curved track, including reversed curves:
[1, 1, 1, 1, 1, -1, 1, 1, 1, 1, 1, -1, 1, 1, 1, 1, 1, -1]
Found 1 unique valid circuits.
0.108705 seconds (524.53 k allocations: 104.014 MiB, 10.93% gc time)
For N of 18 and curved track, excluding reversed curves:
[1, 1, 1, 1, 1, -1, 1, 1, 1, 1, 1, -1, 1, 1, 1, 1, 1, -1]
Found 1 unique valid circuits.
0.098171 seconds (524.57 k allocations: 104.022 MiB, 14.81% gc time)
For N of 20 and curved track, including reversed curves:
Line 872 ⟶ 1,184:
[1, 1, 1, 1, -1, 1, 1, 1, 1, -1, 1, 1, 1, 1, -1, 1, 1, 1, 1, -1]
Found 6 unique valid circuits.
0.542609 seconds (2.10 M allocations: 448.222 MiB, 16.18% gc time)
For N of 20 and curved track, excluding reversed curves:
Line 881 ⟶ 1,194:
[1, 1, 1, 1, -1, 1, 1, 1, 1, -1, 1, 1, 1, 1, -1, 1, 1, 1, 1, -1]
Found 6 unique valid circuits.
0.524247 seconds (2.10 M allocations: 448.411 MiB, 17.80% gc time)
For N of 22 and curved track, including reversed curves:
[1, 1, 1, 1, 1, 1, 1, -1, -1, 1, 1, 1, 1, 1, -1, 1, 1, 1, 1, 1, -1, -1]
[1, 1, 1, 1, 1, 1, -1, -1, 1, 1, 1, 1, 1, -1, 1, 1, 1, 1, -1, 1, 1, -1]
[1, 1, 1, 1, 1, 1, -1, 1, 1, -1, 1, 1, 1, 1, -1, 1, 1, 1, 1, 1, -1, -1]
[1, 1, 1, 1, 1, -1, 1, 1, 1, -1, 1, 1, 1, -1, 1, 1, 1, 1, 1, -1, 1, -1]
[1, 1, 1, 1, 1, -1, 1, 1, -1, 1, 1, 1, 1, -1, 1, 1, 1, 1, -1, 1, 1, -1]
Found 5 unique valid circuits.
2.097615 seconds (8.39 M allocations: 1.875 GiB, 19.04% gc time)
For N of 22 and curved track, excluding reversed curves:
[1, 1, 1, 1, 1, 1, 1, -1, -1, 1, 1, 1, 1, 1, -1, 1, 1, 1, 1, 1, -1, -1]
[1, 1, 1, 1, 1, 1, -1, 1, 1, -1, 1, 1, 1, 1, -1, 1, 1, 1, 1, 1, -1, -1]
[1, 1, 1, 1, 1, -1, 1, 1, 1, -1, 1, 1, 1, -1, 1, 1, 1, 1, 1, -1, 1, -1]
[1, 1, 1, 1, 1, -1, 1, 1, -1, 1, 1, 1, 1, -1, 1, 1, 1, 1, -1, 1, 1, -1]
Found 4 unique valid circuits.
2.079754 seconds (8.39 M allocations: 1.875 GiB, 18.72% gc time)
For N of 24 and curved track, including reversed curves:
Line 924 ⟶ 1,255:
[1, 1, 1, -1, 1, 1, 1, -1, 1, 1, 1, -1, 1, 1, 1, -1, 1, 1, 1, -1, 1, 1, 1, -1]
Found 40 unique valid circuits.
8.816823 seconds (33.60 M allocations: 8.010 GiB, 18.48% gc time)
For N of 24 and curved track, excluding reversed curves:
Line 954 ⟶ 1,286:
[1, 1, 1, -1, 1, 1, 1, -1, 1, 1, 1, -1, 1, 1, 1, -1, 1, 1, 1, -1, 1, 1, 1, -1]
Found 27 unique valid circuits.
8.891642 seconds (33.73 M allocations: 8.016 GiB, 18.45% gc time, 1.16% compilation time)
For N of 26 and curved track, including reversed curves:
[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, -1, -1, 1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 1, -1, -1]
[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, -1, -1, 1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 1, 1, -1]
[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, -1, 1, 1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 1, -1, -1]
[1, 1, 1, 1, 1, 1, 1, 1, -1, -1, -1, 1, 1, 1, 1, 1, -1, 1, 1, 1, 1, 1, -1, 1, -1, -1]
[1, 1, 1, 1, 1, 1, 1, 1, -1, -1, 1, -1, 1, 1, 1, 1, 1, -1, 1, 1, 1, 1, 1, -1, -1, -1]
[1, 1, 1, 1, 1, 1, 1, -1, -1, -1, 1, 1, 1, 1, 1, -1, 1, 1, 1, 1, 1, -1, -1, 1, 1, -1]
[1, 1, 1, 1, 1, 1, 1, -1, -1, -1, 1, 1, 1, 1, 1, -1, 1, 1, 1, 1, -1, 1, 1, -1, 1, -1]
[1, 1, 1, 1, 1, 1, 1, -1, 1, -1, -1, 1, 1, 1, 1, 1, -1, 1, 1, 1, 1, 1, -1, -1, 1, -1]
[1, 1, 1, 1, 1, 1, 1, -1, -1, 1, 1, -1, 1,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 1, 1, 1, -1, -1, 1, 1, 1, 1, -1, 1, 1, 1, 1, -1, -1]
[1, 1, 1, 1, 1, -1, -1, 1, 1, 1, 1, -1, 1, 1, 1, -1, 1, 1, -1, 1, 1, 1, 1, -1, 1, -1]
[1, 1, 1, 1, 1, -1, 1, -1, 1, 1, 1, -1, 1, 1, 1, -1, 1, 1, 1, -1, 1, 1, 1, -1, 1, -1]
[1, 1, 1, 1, 1, -1, 1, 1, 1, -1, -1, 1, 1, 1, 1, -1, 1, 1, 1, 1, -1, 1, 1, -1, 1, -1]
[1, 1, 1, 1, 1, -1, 1, 1, -1, 1, 1, -1, 1, 1, 1, -1, 1, 1, 1, 1, -1, 1, 1, -1, 1, -1]
[1, 1, 1, 1, 1, -1, 1, -1, 1, 1, 1, 1, -1, 1, 1, -1, 1, 1, 1, -1, 1, 1, 1, 1, -1, -1]
[1, 1, 1, 1, 1, -1, 1, 1, 1, -1, -1, 1, 1, 1, 1, 1, -1, 1, 1, -1, 1, 1, 1, 1, -1, -1]
[1, 1, 1, 1, 1, -1, 1, 1, -1, 1, 1, -1, 1, 1, 1, 1, -1, 1, 1, -1, 1, 1, 1, 1, -1, -1]
[1, 1, 1, 1, 1, -1, 1, 1, -1, 1, 1, 1, -1, 1, 1, -1, 1, 1, 1, 1, -1, 1, 1, 1, -1, -1]
[1, 1, 1, 1, -1, 1, 1, -1, 1, 1, 1, -1, 1, 1, 1, -1, 1, 1, -1, 1, 1, 1, 1, -1, 1, -1]
[1, 1, 1, 1, -1, 1, 1, -1, 1, 1, 1, -1, 1, 1, -1, 1, 1, 1, 1, -1, 1, 1, -1, 1, 1, -1]
Found 58 unique valid circuits.
36.909355 seconds (134.32 M allocations: 34.024 GiB, 18.53% gc time, 0.04% compilation time)
For N of 26 and curved track, excluding reversed curves:
[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, -1, -1, 1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 1, -1, -1]
[1, 1, 1, 1, 1, 1, 1, 1,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 1, 1, -1, 1, 1, -1, 1, 1, 1, 1, -1, 1, 1, -1, 1, 1, 1, 1, -1, -1]
[1, 1, 1, 1, 1, -1, 1, 1, -1, 1, 1, -1, 1, 1, 1, -1, 1, 1, 1, 1, -1, 1, 1, -1, 1, -1]
[1, 1, 1, 1, 1, -1, 1, 1, -1, 1, -1, 1, 1, 1, 1, -1, 1, 1, 1, 1, -1, 1, -1, 1, 1, -1]
[1, 1, 1, 1, 1, -1, 1, -1, 1, 1, 1, 1, 1, -1, -1, 1, 1, 1, 1, -1, 1, 1, 1, 1, -1, -1]
[1, 1, 1, 1, 1, -1, 1, -1, 1, 1, 1, 1, -1, 1, 1, -1, 1, 1, 1, -1, 1, 1, 1, 1, -1, -1]
[1, 1, 1, 1, 1, -1, 1, -1, 1, 1, 1, -1, 1, 1, 1, -1, 1, 1, 1, -1, 1, 1, 1, -1, 1, -1]
[1, 1, 1, 1, -1, 1, 1, -1, 1, 1, 1, -1, 1, 1, 1, -1, 1, 1, -1, 1, 1, 1, 1, -1, 1, -1]
[1, 1, 1, 1, -1, 1, 1, -1, 1, 1, 1, -1, 1, 1, -1, 1, 1, 1, 1, -1, 1, 1, -1, 1, 1, -1]
Found 35 unique valid circuits.
36.537159 seconds (134.29 M allocations: 34.017 GiB, 18.66% gc time)
For N of 28 and curved track, including reversed curves:
Found 293 unique valid circuits.
152.393778 seconds (539.33 M allocations: 144.659 GiB, 18.92% gc time)
For N of 28 and curved track, excluding reversed curves:
Found 174 unique valid circuits.
153.737110 seconds (538.62 M allocations: 144.470 GiB, 18.69% gc time)
For N of
Found
603.015572 seconds (2.16 G allocations: 611.883 GiB, 19.12% gc time, 0.00% compilation time)
For N of 30 and curved track, excluding reversed curves:
Found 357 unique valid circuits.4
588.433178 seconds (2.16 G allocations: 610.226 GiB, 19.45% gc time)
For N of 32 and curved track, including reversed curves:
Found 2793 unique valid circuits.
1010.080701 seconds (8.84 G allocations: 2.703 TiB, 14.50% gc time)
For N of 32 and curved track, excluding reversed curves:
Found 1485 unique valid circuits.
1333.508776 seconds (8.73 G allocations: 2.669 TiB, 16.66% gc time)
For N of 34 and curved track, including reversed curves:
Found 7797 unique valid circuits.
6864.782575 seconds (36.46 G allocations: 11.141 TiB, 18.28% gc time, 0.00% compilation time)
For N of 34 and curved track, excluding reversed curves:
Found 3975 unique valid circuits.
5092.741859 seconds (35.46 G allocations: 10.836 TiB, 18.86% gc time, 0.00% compilation time)
For N of 36 and curved track, including reversed curves:
Found 30117 unique valid circuits.
45086.603365 seconds (170.55 G allocations: 57.081 TiB, 22.00% gc time)
For N of 36 and curved track, excluding reversed curves:
Found 15391 unique valid circuits.
45082.100206 seconds (154.85 G allocations: 51.828 TiB, 21.72% gc time)
</pre>
Line 971 ⟶ 1,433:
{{trans|Java}}
It takes several minutes to get up to n = 32. I called it a day after that!
<
const val RIGHT = 1
Line 1,098 ⟶ 1,560:
for (n in 12..32 step 4) circuits(n, 0)
circuits(12, 4)
}</
{{out}}
Line 1,136 ⟶ 1,598:
It took about 2 min 25 s to get the result for a maximum of 32 and 41 min 15 s for a maximum of 36.
<
type
Line 1,263 ⟶ 1,725:
for n in countup(12, 36, 4):
circuits(n, 0)
circuits(12, 4)</
{{out}}
Line 1,297 ⟶ 1,759:
{{trans|Raku}}
{{libheader|ntheory}}
<
use warnings;
use feature 'say';
Line 1,367 ⟶ 1,829:
allvalidcircuits($_, True) for 12, 16, 20;
allvalidcircuits($_, True, True) for 4, 6, 8;</
{{out}}
<pre>For N of 12 and curved track:
Line 1,406 ⟶ 1,868:
=={{header|Phix}}==
{{trans|Go}}
<!--<
<span style="color: #008080;">with</span> <span style="color: #008080;">javascript_semantics</span>
<span style="color: #008080;">constant</span> <span style="color: #000000;">right</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">1</span><span style="color: #0000FF;">,</span>
Line 1,557 ⟶ 2,019:
<span style="color: #008080;">end</span> <span style="color: #008080;">for</span>
<span style="color: #000000;">circuits</span><span style="color: #0000FF;">(</span><span style="color: #000000;">12</span><span style="color: #0000FF;">,</span><span style="color: #000000;">4</span><span style="color: #0000FF;">)</span>
<!--</
{{out}}
<pre>
Line 1,586 ⟶ 2,048:
=={{header|Python}}==
<
import numpy as np
from numpy import sin, cos, pi
Line 1,732 ⟶ 2,194:
sols.append(s)
draw_all(sols[:40])</
=={{header|Racket}}==
Line 1,739 ⟶ 2,201:
Made functional, so builds the track up with lists. A bit more expense spent copying vectors, but this solution avoids mutation (except internally in <code>vector+=</code> . Also got rid of the maximum workload counter.
<
(define-syntax-rule (vector+= v idx i)
Line 1,809 ⟶ 2,271:
(gen 20)
(gen 24)
(gen 12 4))</
{{out}}
Line 1,843 ⟶ 2,305:
{{trans|Julia}}
<syntaxhighlight lang="raku"
# 20200406 Raku programming solution
Line 1,895 ⟶ 2,357:
allvalidcircuits($_, $_ < 28) for 12, 16, 20; # 12, 16 … 36
allvalidcircuits($_, $_ < 12, True) for 4, 6, 8; # 4, 6 … 16;</
{{out}}
<pre>For N of 12 and curved track:
Line 1,936 ⟶ 2,398:
{{trans|Kotlin}}
<
case left = -1, straight, right
}
Line 2,111 ⟶ 2,573:
}
circuits(nCurved: 12, nStraight: 4)</
{{out}}
Line 2,142 ⟶ 2,604:
=={{header|Wren}}==
{{trans|
{{libheader|Wren-
{{libheader|Wren-math}}
Terminal output only.
A tough task for the Wren interpreter requiring about 7 minutes 48 seconds to run. Unlike the Julia example, I've not attempted the straight track for N = 16 (which I estimate would take about an hour in isolation) and have not tried to go beyond N = 24.
<syntaxhighlight lang="wren">import "./seq" for Lst
import "./math" for Int, Nums
// Returns whether 'a' and 'b' are approximately equal within a tolerance of 'tol'.
var IsApprox = Fn.new { |a, b, tol| (a - b).abs <= tol }
// Returns whether a1 < a2 where 'a1' and 'a2' are lists of numbers.
var isLess = Fn.new { |a1, a2|
if (pair[0] > pair[1]) return false
}
return
}
// Represents a 2D point.
class Point {
construct new(x, y) {
_x = x
_y = y
}
x { _x }
y { _y }
+(other) { Point.new(this.x + other.x, this.y + other.y) }
==(other) { IsApprox.call(this.x, other.x, 0.01) && IsApprox.call(this.y, other.y, 0.01) }
toString { "(%(_x), %(_y))" }
}
// A curve section 30 degrees is 1/12 of a circle angle or π/6 radians.
var twelveSteps = List.filled(12, null)
for (a in 0..11) twelveSteps[a] = Point.new((Num.pi * (a+1)/6).sin, (Num.pi * (a+1)/6).cos)
// A straight section 90 degree angle is 1/4 of a circle angle or π/2 radians.
for (a in 0..3) fourSteps[a] = Point.new((Num.pi * (a+1)/2).sin, (Num.pi * (a+1)/2).cos)
// Returns whether 'turns' and 'groupMember' are in an equivalence group.
var isInEquivalenceGroup = Fn.new { |turns, groupMember, reversals|
if (Lst.areEqual(groupMember, turns)) return true
var
for (i in 1...turns.count) {
if (Lst.areEqual(groupMember, Lst.rshift(turns2, 1))) return true
}
if (Lst.areEqual(groupMember, invTurns)) return true
for (i in 1...invTurns.count) {
if (Lst.areEqual(groupMember, Lst.rshift(invTurns, 1))) return true
}
if (reversals) {
var revTurns = turns[-1..0]
if (Lst.areEqual(groupMember, revTurns)) return true
var revTurns2 = revTurns.toList
for (i in 1...revTurns.count) {
if (Lst.areEqual(groupMember, Lst.rshift(revTurns2, 1))) return true
}
invTurns = revTurns.map { |e| (e == 0) ? 0 : -e }.toList
if (Lst.areEqual(groupMember, invTurns)) return true
for (i in 1...invTurns.count) {
if (Lst.areEqual(groupMember, Lst.rshift(invTurns, 1))) return true
}
}
return false
}
// Returns the maximum member of the equivalence group containing 'turns'.
var maximumOfSymmetries = Fn.new { |turns, groupsFound, reversals|
var maxOfGroup = turns.toList
for (i in 0...turns.count) {
if (isLess.call(maxOfGroup, t)) maxOfGroup = t
}
var invTurns = turns.map { |e| (e == 0) ? 0 : -e }
for (i in 0...invTurns.count) {
groupsFound[t.toString] = true
if (isLess.call(maxOfGroup, t)) maxOfGroup = t
}
if (reversals) {
for (i in 0...revTurns.count) {
if (isLess.call(maxOfGroup, t))
var revInvTurns = revTurns.map { |e| (e == 0) ? 0 : -e }
for
var t = Lst.rshift(revInvTurns.toList, i)
groupsFound[t.toString] = true
if (isLess.call(maxOfGroup, t)) maxOfGroup = t
}
}
return maxOfGroup
}
// Returns true if the path of 'turns' returns to starting point, and on that return is
// moving in a direction opposite to the starting direction.
var isClosedPath = Fn.new { |turns, straight, start|
if ((Nums.sum(turns) % (straight ? 4 : 12)) != 0) return false
var angle = 0
var point = Point.new(start.x, start.y)
if (straight) {
for (turn in turns) {
point = point + fourSteps[angle % 4]
} else {
for
point = point + twelveSteps[angle % 12]
}
}
return point == start
}
// Finds and returns all valid circuits on the following basis.
//
// Count the complete circuits by their equivalence groups. Show the unique
// highest sorting lists from each equivalence group if verbose.
//
// Use 30 degree curved track if straight is false, otherwise straight track.
//
// Allow reversed circuits if otherwise in another grouup if reversals is false,
// otherwise do not consider reversed order lists unique.
var allValidCircuits = Fn.new { |n, verbose, straight, reversals|
var found = []
var groupMembersFound = {}
var t1 = straight ? "straight" : "curved"
var t2 = (reversals ? "excl" : "incl") + "uding reversed curves: "
System.print("\nFor N of %(n) and %(t1) track, %(t2)")
for (i in 0..(straight ? 3.pow(n)-1 : 2.pow(n)-1)) {
var turns
if (straight) {
var digs = Int.digits(i, 3)[-1..0]
if (digs.count < n) digs = digs + ([0] * (n - digs.count))
turns = digs.map { |d| (d == 0) ? 0 : ((d == 1) ? 1 : -1) }.toList
} else {
var digs = Int.digits(i, 2)[-1..0]
if (digs.count < n ) digs = digs + ([0] * (n - digs.count))
turns = digs.map { |d| (d == 0) ? 1 : -1 }.toList
}
if (isClosedPath.call(turns, straight, Point.new(0, 0)) &&
!groupMembersFound.containsKey(turns.toString)) {
if (found.isEmpty || found.all { |t| !isInEquivalenceGroup.call(turns, t, false) }) {
var canon = maximumOfSymmetries.call(turns, groupMembersFound, reversals)
if (verbose) System.print(canon)
found.add(canon)
}
}
}
System.print("Found %(found.count) unique valid circuit(s).")
return found
}
var n = 4
while (n <= 24) {
for (rev in [false, true]) {
for (str in [false, true]) {
if (str && n > 14) continue
allValidCircuits.call(n, !str, str, rev)
}
}
n = n + 2
}</syntaxhighlight>
{{out}}
<pre>
For N of 4 and curved track, including reversed curves:
Found 0 unique valid circuit(s).
For N of 4 and straight track, including reversed curves:
Found 1 unique valid circuit(s).
For N of 4 and curved track, excluding reversed curves:
Found 0 unique valid circuit(s).
For N of 4 and straight track, excluding reversed curves:
Found 1 unique valid circuit(s).
For N of 6 and curved track, including reversed curves:
Found 0 unique valid circuit(s).
For N of 6 and straight track, including reversed curves:
Found 1 unique valid circuit(s).
For N of 6 and curved track, excluding reversed curves:
Found 0 unique valid circuit(s).
For N of 6 and straight track, excluding reversed curves:
Found 1 unique valid circuit(s).
For N of 8 and curved track, including reversed curves:
Found 0 unique valid circuit(s).
For N of 8 and straight track, including reversed curves:
Found 7 unique valid circuit(s).
For N of 8 and curved track, excluding reversed curves:
Found 0 unique valid circuit(s).
For N of 8 and straight track, excluding reversed curves:
Found 7 unique valid circuit(s).
For N of 10 and curved track, including reversed curves:
Found 0 unique valid circuit(s).
For N of 10 and straight track, including reversed curves:
Found 23 unique valid circuit(s).
For N of 10 and curved track, excluding reversed curves:
Found 0 unique valid circuit(s).
For N of 10 and straight track, excluding reversed curves:
Found 15 unique valid circuit(s).
For N of 12 and curved track, including reversed curves:
[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]
Found 1 unique valid circuit(s).
For N of 12 and straight track, including reversed curves:
Found 141 unique valid circuit(s).
For N of 12 and curved track, excluding reversed curves:
[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]
Found 1 unique valid circuit(s).
For N of 12 and straight track, excluding reversed curves:
Found 95 unique valid circuit(s).
For N of 14 and curved track, including reversed curves:
Found 0 unique valid circuit(s).
For N of 14 and straight track, including reversed curves:
Found 871 unique valid circuit(s).
For N of 14 and curved track, excluding reversed curves:
Found 0 unique valid circuit(s).
For N of 14 and straight track, excluding reversed curves:
Found 465 unique valid circuit(s).
For N of 16 and curved track, including reversed curves:
[1, 1, 1, 1, 1, 1, 1, -1, 1, 1, 1, 1, 1, 1, 1, -1]
Found 1 unique valid circuit(s).
For N of 16 and curved track, excluding reversed curves:
[1, 1, 1, 1, 1, 1, 1, -1, 1, 1, 1, 1, 1, 1, 1, -1]
Found 1 unique valid circuit(s).
For N of 18 and curved track, including reversed curves:
[1, 1, 1, 1, 1, -1, 1, 1, 1, 1, 1, -1, 1, 1, 1, 1, 1, -1]
Found 1 unique valid circuit(s).
For N of 18 and curved track, excluding reversed curves:
[1, 1, 1, 1, 1, -1, 1, 1, 1, 1, 1, -1, 1, 1, 1, 1, 1, -1]
Found 1 unique valid circuit(s).
For N of 20 and curved track, including reversed curves:
[1, 1, 1, 1, 1, 1, 1, 1, -1, -1, 1, 1, 1, 1, 1, 1, 1, 1, -1, -1]
[1, 1, 1, 1, 1, 1, 1, -1, 1, 1, -1, 1, 1, 1, 1, 1, 1, 1, -1, -1]
[1, 1, 1, 1, 1, 1, 1, -1, 1, -1, 1, 1, 1, 1, 1, 1, 1, -1, 1, -1]
[1, 1, 1, 1, 1, 1, -1, 1, 1, -1, 1, 1, 1, 1, 1, 1, -1, 1, 1, -1]
[1, 1, 1, 1, 1, -1, 1, 1, 1, -1, 1, 1, 1, 1, 1, -1, 1, 1, 1, -1]
[1, 1, 1, 1, -1, 1, 1, 1, 1, -1, 1, 1, 1, 1, -1, 1, 1, 1, 1, -1]
Found 6 unique valid circuit(s).
For N of 20 and curved track, excluding reversed curves:
[1, 1, 1, 1, 1, 1, 1, 1, -1, -1, 1, 1, 1, 1, 1, 1, 1, 1, -1, -1]
[1, 1, 1, 1, 1, 1, 1, -1, 1, 1, -1, 1, 1, 1, 1, 1, 1, 1, -1, -1]
[1, 1, 1, 1, 1, 1, 1, -1, 1, -1, 1, 1, 1, 1, 1, 1, 1, -1, 1, -1]
[1, 1, 1, 1, 1, 1, -1, 1, 1, -1, 1, 1, 1, 1, 1, 1, -1, 1, 1, -1]
[1, 1, 1, 1, 1, -1, 1, 1, 1, -1, 1, 1, 1, 1, 1, -1, 1, 1, 1, -1]
[1, 1, 1, 1, -1, 1, 1, 1, 1, -1, 1, 1, 1, 1, -1, 1, 1, 1, 1, -1]
Found 6 unique valid circuit(s).
For N of 22 and curved track, including reversed curves:
[1, 1, 1, 1, 1, 1, 1, -1, -1, 1, 1, 1, 1, 1, -1, 1, 1, 1, 1, 1, -1, -1]
[1, 1, 1, 1, 1, 1, -1, -1, 1, 1, 1, 1, 1, -1, 1, 1, 1, 1, -1, 1, 1, -1]
[1, 1, 1, 1, 1, 1, -1, 1, 1, -1, 1, 1, 1, 1, -1, 1, 1, 1, 1, 1, -1, -1]
[1, 1, 1, 1, 1, -1, 1, 1, 1, -1, 1, 1, 1, -1, 1, 1, 1, 1, 1, -1, 1, -1]
[1, 1, 1, 1, 1, -1, 1, 1, -1, 1, 1, 1, 1, -1, 1, 1, 1, 1, -1, 1, 1, -1]
Found 5 unique valid circuit(s).
For N of 22 and curved track, excluding reversed curves:
[1, 1, 1, 1, 1, 1, 1, -1, -1, 1, 1, 1, 1, 1, -1, 1, 1, 1, 1, 1, -1, -1]
[1, 1, 1, 1, 1, 1, -1, 1, 1, -1, 1, 1, 1, 1, -1, 1, 1, 1, 1, 1, -1, -1]
[1, 1, 1, 1, 1, -1, 1, 1, 1, -1, 1, 1, 1, -1, 1, 1, 1, 1, 1, -1, 1, -1]
[1, 1, 1, 1, 1, -1, 1, 1, -1, 1, 1, 1, 1, -1, 1, 1, 1, 1, -1, 1, 1, -1]
Found 4 unique valid circuit(s).
For N of 24 and curved track, including reversed curves:
[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]
[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1]
[1, 1, 1, 1, 1, 1, 1, 1, 1, -1, -1, -1, 1, 1, 1, 1, 1, 1, 1, 1, 1, -1, -1, -1]
[1, 1, 1, 1, 1, 1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-1, 1, 1, 1, 1, 1, -1, 1, -1, 1, 1, 1, 1, 1, -1, 1, -1]
[1, 1, 1, 1, 1, -1, 1, 1, 1, -1, 1, -1, 1, 1, 1, 1, 1, -1, 1, 1, 1, -1, 1, -1]
[1, 1, 1, 1, 1, -1, 1, 1, 1, 1, -1, -1, 1, 1, 1, 1, 1, -1, 1, 1, 1, 1, -1, -1]
[1, 1, 1, 1, 1, -1, 1, 1, 1, -1, 1, 1, -1, 1, 1, 1, 1, -1, 1, 1, 1, 1, -1, -1]
[1, 1, 1, 1, -1, 1, 1, 1, 1, -1, 1, -1, 1, 1, 1, 1, -1, 1, 1, 1, 1, -1, 1, -1]
[1, 1, 1, 1, -1, 1, 1, -1, 1, 1, 1, -1, 1, 1, 1, 1, -1, 1, 1, -1, 1, 1, 1, -1]
[1, 1, 1, 1, -1, 1, 1, -1, 1, 1, 1, 1, -1, 1, 1, -1, 1, 1, 1, 1, -1, 1, 1, -1]
[1, 1, 1, 1, -1, 1, 1, 1, -1, 1, 1, -1, 1, 1, 1, 1, -1, 1, 1, 1, -1, 1, 1, -1]
[1, 1, 1, -1, 1, 1, 1, -1, 1, 1, 1, -1, 1, 1, 1, -1, 1, 1, 1, -1, 1, 1, 1, -1]
Found 40 unique valid circuit(s).
For N of 24 and curved track, excluding reversed curves:
[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]
[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1]
[1, 1, 1, 1, 1, 1, 1, 1, 1, -1, -1, -1, 1, 1, 1, 1, 1, 1, 1, 1, 1, -1, -1, -1]
[1, 1, 1, 1, 1, 1, 1, 1, -1, 1, -1, -1, 1, 1, 1, 1, 1, 1, 1, 1, -1, 1, -1, -1]
[1, 1, 1, 1, 1, 1, 1, 1, -1, -1, 1, 1, 1, -1, 1, 1, 1, 1, 1, 1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1, 1, -1, -1]
[1, 1, 1, 1, 1, -1, 1, 1, 1, -1, 1, -1, 1, 1, 1, 1, 1, -1, 1, 1, 1, -1, 1, -1]
[1, 1, 1, 1, 1, -1, 1, 1, -1, 1, 1, 1, 1, -1, 1, 1, -1, 1, 1, 1, 1, 1, -1, -1]
[1, 1, 1, 1, 1, -1, 1, 1, -1, 1, 1, -1, 1, 1, 1, 1, 1, -1, 1, 1, -1, 1, 1, -1]
[1, 1, 1, 1, 1, -1, 1, -1, 1, 1, 1, 1, 1, -1, 1, -1, 1, 1, 1, 1, 1, -1, 1, -1]
[1, 1, 1, 1, -1, 1, 1, 1, 1, -1, 1, -1, 1, 1, 1, 1, -1, 1, 1, 1, 1, -1, 1, -1]
[1, 1, 1, 1, -1, 1, 1, 1, -1, 1, 1, -1, 1, 1, 1, 1, -1, 1, 1, 1, -1, 1, 1, -1]
[1, 1, 1, 1, -1, 1, 1, -1, 1, 1, 1, 1, -1, 1, 1, -1, 1, 1, 1, 1, -1, 1, 1, -1]
[1, 1, 1, -1, 1, 1, 1, -1, 1, 1, 1, -1, 1, 1, 1, -1, 1, 1, 1, -1, 1, 1, 1, -1]
Found 27 unique valid circuit(s).
</pre>
=={{header|zkl}}==
{{trans|EchoLisp}}
<
// The nb of right turns in direction i
// must be = to nb of right turns in direction i+6 (opposite)
Line 2,381 ⟶ 3,057:
else println("Number of circuits C%,d,%d : %d".fmt(maxn,straight,_circuits.len()));
if(_circuits.len()<20) _circuits.apply2(T(T("toString",*),"println"));
}</
<
gen(16); println();
gen(20); println();
gen(24); println();
gen(12,4);</
{{out}}
<pre>
|