Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw

Re: How can I improve this?

by young perlhopper (Scribe)
on Jul 25, 2000 at 07:14 UTC ( #24237=note: print w/replies, xml ) Need Help??

in reply to How can I improve this?

One thing you could do is simply generate all permutations, and then sort them. i.e.

@array = magical_permutation_generating_sub; @sorted_array = sort srtsub @array; sub srtsub { #strip out everything that's not a zero, making it easy #to compare the number of zeros ($A = $a) =~ s/[^0]//; ($B = $b) =~ s/[^0]//; return ($A gt $B); }
This presumes that your only sorting criteria is the number of zeros. But if you have more, just add them to srtsub.

Good luck,

p.s. goshdarnit lhoward beat me to it and posted better code. I'm gonna leave mine up though cause i think its a little easier for somebody who (i gather) has a C background to grok.

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (7)
As of 2016-10-23 12:32 GMT
Find Nodes?
    Voting Booth?
    How many different varieties (color, size, etc) of socks do you have in your sock drawer?

    Results (301 votes). Check out past polls.