Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re^3: generating permutations

by tybalt89 (Monsignor)
on Mar 31, 2017 at 22:35 UTC ( [id://1186649] : note . print w/replies, xml ) Need Help??


in reply to Re^2: generating permutations
in thread generating permutations

Here's a version that uses a separate array to mark when a item is used instead of building and destroying anon arrays.

#!/usr/bin/perl # http://perlmonks.org/?node_id=1186402 use strict; use warnings; my @items = qw( apple banana orange ); my @used; sub permute { @_ == @items and return print "@_\n"; $used[$_]++ || permute(@_, $items[$_]), $used[$_]-- for 0 .. $#items +; } permute();