Jump to content

Cycles of a permutation: Difference between revisions

m
syntax highlighting fixup automation
m (→‎{{header|Phix}}: better constants, camelCase->under_scores, eliminated 15s, added a tagstart builtin)
m (syntax highlighting fixup automation)
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
duplicate the cycles as written in examples given in the task.
<langsyntaxhighlight lang="julia">""" A Perm is a permutation in one-line form. `a` is a shuffled gapless 1-based range of Int. """
struct Perm
a::Vector{Int}
Line 272:
 
testAlfBettyPerms()
</langsyntaxhighlight> {{out}}
<pre>
On Thursdays Alf and Betty should rearrange
Line 340:
=={{header|Phix}}==
{{trans|Wren}}
<!--<langsyntaxhighlight Phixlang="phix">(phixonline)-->
<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>
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;">end</span> <span style="color: #008080;">for</span>
<!--</langsyntaxhighlight>-->
Output identical to Julia/Wren
 
=={{header|Python}}==
{{trans|Julia}}
<langsyntaxhighlight lang="python">""" For Rosetta Code task Cycles_of_a_permutation """
 
from math import lcm # in python 3.9+
Line 706:
SPE = permutestring(SPE, PFRI)
print(str(i+1).rjust(2), ' ', SPE, '\n' if i == 8 else '')
</langsyntaxhighlight> {{out}}
<pre>
Same as Quackery.
Line 713:
=={{header|Quackery}}==
 
<langsyntaxhighlight Quackerylang="quackery">( Glossary
--------
Line 1,079:
echo sp
friday cycle cypermute dup echo$ cr ]
drop</langsyntaxhighlight>
 
{{out}}
Line 1,155:
 
I've also stuck rigidly to the Quackery entry's examples for ease of comparison.
<langsyntaxhighlight lang="ecmascript">import "./math" for Int
import "./fmt" for Fmt
 
Line 1,395:
prev = PC.cyclePermute(prev, cycles3)
System.print(prev)
}</langsyntaxhighlight>
 
{{out}}
10,333

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.