RosettaCodeData/Task/Permutations/Ursala/permutations-1.ursala
Ingy döt Net b83f433714 tasks a-s
2013-04-10 23:57:08 -07:00

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