Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re: Very Large Hex Combinations

by ikegami (Pope)
on Aug 04, 2005 at 14:57 UTC ( #480855=note: print w/ replies, xml ) Need Help??


in reply to Very Large Hex Combinations

People have suggested ways of working with numbers. I think it's faster to work with strings in this case (because it reduces greatly the number of calls to sprintf):

my @bytes = map { sprintf('%02X', $_) } 0..255; foreach my $i (@bytes) { foreach my $j (@bytes) { foreach my $k (@bytes) { foreach my $l (@bytes) { foreach my $m (@bytes) { foreach my $n (@bytes) { print("$i$j$k$l$m$n\n"); }}}}}}

Or you could use NestedLoops in Algorithm::Loops:

use Algorithm::Loops qw( NestedLoops ); my @bytes = map { sprintf('%02X', $_) } 0..255; my $num_bytes = 6; NestedLoops( [ ( [ @bytes ] ) x $bytes ], sub { print(join('', @_), "\n"); } );


Comment on Re: Very Large Hex Combinations
Select or Download Code
Re^2: Very Large Hex Combinations
by danambroseUK (Beadle) on Aug 04, 2005 at 15:08 UTC
    Thanks all for the *very* quick replies....


    Ikegami's idea with using strings seems to be quicker - my next question is how would I expand the bellow code to produce larger hex patterns?

    my @bytes = map { sprintf('%02X', $_) } 0..255; foreach my $i (@bytes) { foreach my $j (@bytes) { foreach my $k (@bytes) { foreach my $l (@bytes) { foreach my $m (@bytes) { foreach my $n (@bytes) { print("$i$j$k$l$m$n\n"); }}}}}}


    Many thanks
    Dan
      How large? That produces all patterns from 000000000000 to FFFFFFFFFFFF. Add more loops to make it bigger, or increase $num_bytes in my second snippet.
        i think one should use recursion here, something like this maybe
        use strict; use warnings; my @charset = ( 0..9, "A".."F" ); rec( 8 ); sub rec { my $deep = shift; my $string = shift || ''; if ( $deep-- ) { for my $char ( @charset ) { rec( $deep, $string . $char ); } } else { print "$string\n"; } }
        Its a crazy idea but what I am trying to do is create every combination possible of a 640x480 bitmap file.

        Yes this would take forever to do - but just imagine if every photo was created - we would have every photo of everything. Every photo ever taken and every photo to be taken- Effectivly a time machine!!

        Jokes aside, how would this be achieved?


        Thanks,
        Dan

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (10)
As of 2014-09-16 16:27 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (34 votes), past polls