Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re^4: Generate all unique combinations of 1 and 0 using specified length of "0"-string and count of 1's -- permutations

by Discipulus (Abbot)
on Sep 18, 2020 at 10:05 UTC ( #11121909=note: print w/replies, xml ) Need Help??


in reply to Re^3: Generate all unique combinations of 1 and 0 using specified length of "0"-string and count of 1's -- permutations
in thread Generate all unique combinations of 1 and 0 using specified length of "0"-string and count of 1's

yes thanks choroba and hippo, my code presented above is blatantly wrong :)

Can I add a %seen to repair my sin?

use strict; use warnings; use feature 'say'; use Algorithm::Combinatorics qw(permutations); my $zeros = 7; my $ones = 3; my %seen; # this is really ugly # say join '', @$_ for grep{ !$seen{join('', @$_)}++ } permutations( [ + (0) x $zeros, (1) x $ones] ); # a little nicer say for grep { !$seen{$_}++ } map{join '', @$_} permutations( [(0) x $ +zeros, (1) x $ones] );

Now the cure is worst than the disease, but runs ok

L*

There are no rules, there are no thumbs..
Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.
  • Comment on Re^4: Generate all unique combinations of 1 and 0 using specified length of "0"-string and count of 1's -- permutations
  • Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (3)
As of 2022-12-03 20:19 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?