Permutations: Difference between revisions
→{{header|langur}}
m (→{{header|Wren}}: Minor tidy) |
Langurmonkey (talk | contribs) |
||
(4 intermediate revisions by 2 users not shown) | |||
Line 5,691:
This follows the Go language non-recursive example, but is not limited to integers, or even to numbers.
▲<syntaxhighlight lang="langur">val .factorial = f if(.x < 2: 1; .x x self(.x - 1))
▲val .permute = f(.arr) {
▲ if not isArray(.arr): throw "expected array"
val .limit = 10
if len(.
var .elements = .
var .ordinals = pseries len .elements
Line 5,708 ⟶ 5,705:
var .i, .j
for[.p=[.
.i = .n - 1
.j = .n
Line 5,732 ⟶ 5,729:
for .e in .permute([1, 3.14, 7]) {
writeln .e
}
{{out}}
Line 9,411 ⟶ 9,409:
st> 'Abc' permutations contents
('bcA' 'cbA' 'cAb' 'Acb' 'bAc' 'Abc' )
</syntaxhighlight>
=={{header|Standard ML}}==
<syntaxhighlight lang="sml">
fun interleave x [] = [[x]]
| interleave x (y::ys) = (x::y::ys) :: (List.map (fn a => y::a) (interleave x ys))
fun perms [] = [[]]
| perms (x::xs) = List.concat (List.map (interleave x) (perms xs))
</syntaxhighlight>
|