Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re: How can I improve this?

by young perlhopper (Scribe)
on Jul 25, 2000 at 07:14 UTC ( [id://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,
Mark

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?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others cooling their heels in the Monastery: (5)
As of 2024-03-28 14:39 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found