28 lines
904 B
Text
28 lines
904 B
Text
templates permutations
|
|
when <=1> do [1] !
|
|
otherwise
|
|
def n: $;
|
|
templates expand
|
|
def p: $;
|
|
1..$n -> \(def k: $;
|
|
[$p(1..$k-1)..., $n, $p($k..last)...] !\) !
|
|
end expand
|
|
$n - 1 -> permutations -> expand !
|
|
end permutations
|
|
|
|
templates index&{of:}
|
|
$ -> \[i](<=$of> $i! \) ...!
|
|
end index
|
|
|
|
def names: ['Baker', 'Cooper', 'Fletcher', 'Miller', 'Smith'];
|
|
|
|
5 -> permutations -> $names($)
|
|
-> \(<?($ -> index&{of: 'Baker'} <~=5>)> $! \)
|
|
-> \(<?($ -> index&{of: 'Cooper'} <~=1>)> $! \)
|
|
-> \(<?($ -> index&{of: 'Fletcher'} <~=1|=5>)> $! \)
|
|
-> \(<?($ -> index&{of: 'Cooper'} <..($ -> index&{of:'Miller'})>)> $! \)
|
|
-> \(<?(($ -> index&{of: 'Smith'}) - ($ -> index&{of:'Fletcher'}) <~=1|=-1>)> $! \)
|
|
-> \(<?(($ -> index&{of: 'Cooper'}) - ($ -> index&{of:'Fletcher'}) <~=1|=-1>)> $! \)
|
|
-> \[i]('$i;:$;$#10;' ! \)
|
|
-> $(last..first:-1)
|
|
-> '$...;$#10;' -> !OUT::write
|