Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

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,
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.


Comment on Re: How can I improve this?
Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (15)
As of 2014-08-01 13:04 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Who would be the most fun to work for?















    Results (19 votes), past polls