Permutations: Difference between revisions

Added GNU make example
m (→‎{{header|Shen}}: add lexical order variation and use the don't-care pattern where appropriate)
(Added GNU make example)
Line 2,995:
• 7.9 Hello 123
• 7.9 123 Hello</lang>
 
=={{header|GNU make}}==
 
Recursive on unique elements
 
<lang make>
#delimiter should not occur inside elements
delimiter=;
#convert list to delimiter separated string
implode=$(subst $() $(),$(delimiter),$(strip $1))
#convert delimiter separated string to list
explode=$(strip $(subst $(delimiter), ,$1))
#enumerate all permutations and subpermutations
permutations0=$(if $1,$(foreach x,$1,$x $(addprefix $x$(delimiter),$(call permutations0,$(filter-out $x,$1)))),)
#remove subpermutations from permutations0 output
permutations=$(strip $(foreach x,$(call permutations0,$1),$(if $(filter $(words $1),$(words $(call explode,$x))),$(call implode,$(call explode,$x)),)))
 
delimiter_separated_output=$(call permutations,a b c d)
$(info $(delimiter_separated_output))
</lang>
 
{{out}}
<pre>a;b;c;d a;b;d;c a;c;b;d a;c;d;b a;d;b;c a;d;c;b b;a;c;d b;a;d;c b;c;a;d b;c;d;a b;d;a;c b;d;c;a c;a;b;d c;a;d;b c;b;a;d c;b;d;a c;d;a;b c;d;b;a d;a;b;c d;a;c;b d;b;a;c d;b;c;a d;c;a;b d;c;b;a</pre>
 
=={{header|Go}}==
Anonymous user