Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re: Combinations with variable length

by ikegami (Pope)
on May 12, 2021 at 15:55 UTC ( #11132499=note: print w/replies, xml ) Need Help??


in reply to Combinations with variable length

for ( 0 .. 2**$n-1 ) { my @combo = map { $_ + 1 } split //, sprintf("%0*b", $n, $_); say "@combo"; }

use Algorithm::Loops qw( NestedLoops ); my $iter = NestedLoops([ map [ 1, 2 ], 1..$n ]); while ( my @combo = $iter->() ) { say "@combo"; }

Seeking work! You can reach me at ikegami@adaelis.com

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11132499]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (3)
As of 2021-08-01 13:13 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My primary motivation for participating at PerlMonks is: (Choices in context)








    Results (8 votes). Check out past polls.

    Notices?