Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"

Re: Let's get lazy

by beretboy (Chaplain)
on Nov 02, 2001 at 03:36 UTC ( #122720=note: print w/replies, xml ) Need Help??

in reply to Let's get lazy

May not be exactly what you are looking for but I wrote this peice of code as a way to find (through brute force) all possible combinations of something (in this case locker combinations, don't ask why). anyway here it is:
#All possible combination generator use strict; use Quantum::Superpositions; open (DUMP, ">combos.txt"); my @list; my $i = 0; while (1) { my $num = int(rand(31)) . "-" . int(rand(31)) . "-" . int(rand(31)); if ($num eq any(@list)) { next; } else { @list[$i] = $num; print "$num "; print DUMP "$num\n"; $i++; } }

"Sanity is the playground of the unimaginative" -Unknown

Replies are listed 'Best First'.
Re: Re: Let's get lazy
by blakem (Monsignor) on Nov 02, 2001 at 04:26 UTC
    Since I don't see the glob trick mentioned in this thread, and I'm not too keen on your pick-random-combos-until-we-think-weve-got-them-all solution, here are two ways to solve the locker combo problem.
    #!/usr/bin/perl -wT use strict; # golfed version using glob my $nums = join(',',1..31); my @list1 = glob("{$nums}-{$nums}-{$nums}"); print "L1: $_\n" for @list1; # more sane way of doing that..... my @list2; for my $i (1..31) { for my $j (1..31) { for my $k (1..31) { push(@list2,"$i-$j-$k"); } } } print "L2: $_\n" for @list2;
    And here is the glob trick used to solve the original problem...
    #!/usr/bin/perl -wT use strict; # one ordering.... my $letters = ',A,C,G,N,T'; my @list1 = grep {/./} glob("{$letters}"x4); print "L1: $_\n" for @list1; # different ordering my $letter2 = 'A,C,G,N,T'; my @list2 = (glob("{$letter2}"x2),glob("{$letter2}"x3),glob("{$letter2 +}"x4)); print "L2: $_\n" for @list2;


Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://122720]
[Corion]: Meh. I need to find myself a better "programming" feed than r/programming (which is just HackerNews reposts and advertisements, very little code). Maybe I should select a list of links that I liked on r/programming and then google for ...
[Corion]: ... an aggregator site that also listed (ideally) all of these links once. And maybe also have an exclude list to blacklist some of the most spammy links that the site may have never mentioned at all

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (7)
As of 2017-07-24 13:19 GMT
Find Nodes?
    Voting Booth?
    I came, I saw, I ...

    Results (354 votes). Check out past polls.