9 lines
488 B
Text
9 lines
488 B
Text
#import std
|
|
|
|
permutations =
|
|
|
|
~&itB^?a( # are both the input argument list and its tail non-empty?
|
|
@ahPfatPRD *= refer ^C( # yes, recursively generate all permutations of the tail, and for each one
|
|
~&a, # insert the head at the first position
|
|
~&ar&& ~&arh2falrtPXPRD), # if the rest is non-empty, recursively insert at all subsequent positions
|
|
~&aNC) # no, return the singleton list of the argument
|