RosettaCodeData/Task/Permutations/Ursala/permutations-1.ursala

10 lines
488 B
Text
Raw Permalink Normal View History

2013-04-10 23:57:08 -07:00
#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