Cycles of a permutation: Difference between revisions
Content added Content deleted
m (→{{header|Phix}}: better constants, camelCase->under_scores, eliminated 15s, added a tagstart builtin) |
Thundergnat (talk | contribs) m (syntax highlighting fixup automation) |
||
Line 131: | Line 131: | ||
is therefore customizable in the code below so as to fit to either format, and the test function's code is specified so as to |
is therefore customizable in the code below so as to fit to either format, and the test function's code is specified so as to |
||
duplicate the cycles as written in examples given in the task. |
duplicate the cycles as written in examples given in the task. |
||
< |
<syntaxhighlight lang="julia">""" A Perm is a permutation in one-line form. `a` is a shuffled gapless 1-based range of Int. """ |
||
struct Perm |
struct Perm |
||
a::Vector{Int} |
a::Vector{Int} |
||
Line 272: | Line 272: | ||
testAlfBettyPerms() |
testAlfBettyPerms() |
||
</ |
</syntaxhighlight> {{out}} |
||
<pre> |
<pre> |
||
On Thursdays Alf and Betty should rearrange |
On Thursdays Alf and Betty should rearrange |
||
Line 340: | Line 340: | ||
=={{header|Phix}}== |
=={{header|Phix}}== |
||
{{trans|Wren}} |
{{trans|Wren}} |
||
<!--< |
<!--<syntaxhighlight lang="phix">(phixonline)--> |
||
<span style="color: #008080;">with</span> <span style="color: #008080;">javascript_semantics</span> |
<span style="color: #008080;">with</span> <span style="color: #008080;">javascript_semantics</span> |
||
<span style="color: #7060A8;">requires</span><span style="color: #0000FF;">(</span><span style="color: #008000;">"1.0.2"</span><span style="color: #0000FF;">)</span> <span style="color: #000080;font-style:italic;">-- (tagstart)</span> |
<span style="color: #7060A8;">requires</span><span style="color: #0000FF;">(</span><span style="color: #008000;">"1.0.2"</span><span style="color: #0000FF;">)</span> <span style="color: #000080;font-style:italic;">-- (tagstart)</span> |
||
Line 546: | Line 546: | ||
<span style="color: #008080;">if</span> <span style="color: #000000;">i</span><span style="color: #0000FF;">>=</span><span style="color: #000000;">9</span> <span style="color: #008080;">then</span> <span style="color: #7060A8;">printf</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"\n"</span><span style="color: #0000FF;">)</span> <span style="color: #008080;">end</span> <span style="color: #008080;">if</span> |
<span style="color: #008080;">if</span> <span style="color: #000000;">i</span><span style="color: #0000FF;">>=</span><span style="color: #000000;">9</span> <span style="color: #008080;">then</span> <span style="color: #7060A8;">printf</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"\n"</span><span style="color: #0000FF;">)</span> <span style="color: #008080;">end</span> <span style="color: #008080;">if</span> |
||
<span style="color: #008080;">end</span> <span style="color: #008080;">for</span> |
<span style="color: #008080;">end</span> <span style="color: #008080;">for</span> |
||
<!--</ |
<!--</syntaxhighlight>--> |
||
Output identical to Julia/Wren |
Output identical to Julia/Wren |
||
=={{header|Python}}== |
=={{header|Python}}== |
||
{{trans|Julia}} |
{{trans|Julia}} |
||
< |
<syntaxhighlight lang="python">""" For Rosetta Code task Cycles_of_a_permutation """ |
||
from math import lcm # in python 3.9+ |
from math import lcm # in python 3.9+ |
||
Line 706: | Line 706: | ||
SPE = permutestring(SPE, PFRI) |
SPE = permutestring(SPE, PFRI) |
||
print(str(i+1).rjust(2), ' ', SPE, '\n' if i == 8 else '') |
print(str(i+1).rjust(2), ' ', SPE, '\n' if i == 8 else '') |
||
</ |
</syntaxhighlight> {{out}} |
||
<pre> |
<pre> |
||
Same as Quackery. |
Same as Quackery. |
||
Line 713: | Line 713: | ||
=={{header|Quackery}}== |
=={{header|Quackery}}== |
||
< |
<syntaxhighlight lang="quackery">( Glossary |
||
-------- |
-------- |
||
Line 1,079: | Line 1,079: | ||
echo sp |
echo sp |
||
friday cycle cypermute dup echo$ cr ] |
friday cycle cypermute dup echo$ cr ] |
||
drop</ |
drop</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
Line 1,155: | Line 1,155: | ||
I've also stuck rigidly to the Quackery entry's examples for ease of comparison. |
I've also stuck rigidly to the Quackery entry's examples for ease of comparison. |
||
< |
<syntaxhighlight lang="ecmascript">import "./math" for Int |
||
import "./fmt" for Fmt |
import "./fmt" for Fmt |
||
Line 1,395: | Line 1,395: | ||
prev = PC.cyclePermute(prev, cycles3) |
prev = PC.cyclePermute(prev, cycles3) |
||
System.print(prev) |
System.print(prev) |
||
}</ |
}</syntaxhighlight> |
||
{{out}} |
{{out}} |