Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re: One Zero variants_without_repetition

by bduggan (Pilgrim)
on Aug 07, 2007 at 15:10 UTC ( [id://631069]=note: print w/replies, xml ) Need Help??


in reply to One Zero variants_without_repetition

A natural way to do this seems to me to think of it as the number of ways of placing the ones in a string of size $ones + $zeros :
use Algorithm::ChooseSubsets; use strict; my $ones = 2; my $twos = 3; my $i = Algorithm::ChooseSubsets->new($ones + $twos,$ones); while (my $x = $i->next) { my %on = map {($_ => 1)} @$x; my @str = map { $on{$_} ? '1' : '0' } (0..$ones+$twos-1); print @str,"\n"; }

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (7)
As of 2024-04-16 06:06 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found