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

Re^2: Very Large Hex Combinations

by danambroseUK (Beadle)
on Aug 04, 2005 at 15:08 UTC ( #480857=note: print w/replies, xml ) Need Help??

in reply to Re: Very Large Hex Combinations
in thread Very Large Hex Combinations

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

Replies are listed 'Best First'.
Re^3: Very Large Hex Combinations
by ikegami (Pope) on Aug 04, 2005 at 15:14 UTC
    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"; } }
        Quite so, since all the loops have the same bounds. ++ed
      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?

        Its a crazy idea but what I am trying to do is create every combination possible of a 640x480 bitmap file.
        After that you could also generate all possible novels up to 500 pages, so I will finally get rid of the monkeys in my basement ;-)

        Seriously, the number of all possible images is *real* huge, and even if you managed to save them somewhere, indexing them would be as difficult as generating them. In order to retrieve a specific image, you would somehow be able to indicate "I want the image whose first pixel is 0xa, whose second pixel is 0x0 ..." and so on with all the pixels. It is more reasonable to just generate it on the fly (and it allows you to save a few gazillion bytes).



        The stupider the astronaut, the easier it is to win the trip to Vega - A. Tucket
        Eh, may I suggest starting with smaller sized pictures? Say, 8x8 bitmaps? Of which there are 18446744073709551616, each taking 8 bytes of storage. You only need 137438953472 disks of 1 Tb each to store them. Suppose you can install one such disk each second, and you never tire, you don't need sleep, you don't need to eat, and don't go to the bathroom. Furthermore, disk companies manage to supply you with enough disks. Then you only need 4355 years to install the disks to store your all your 8x8 bitmaps.

        After doing the 8x8 bitmaps, you might want to tackle the 12x12 bitmaps. If you can install 1Tb of storage each second, you only need 9 * 10^35 years to install your storage.

        One of those photos would reveal that you killed JFK!!! Do you think that the world is prepared for this truth?

        perl -ple'$_=reverse' <<<ti.xittelop@oivalf

        Don't fool yourself.

        Update: Minor brainfart there. The point of the post still holds, but you'll need to multiply all the numbers by 2**( 640 * 480 ):

        142427923839648881629184805134324652164093716404030097299710376120451 134154787190076398812090414510556300740006550934739747222066752231099 294344002591005120626800863471535551485395485528316242619445670424359 449935350841325881969413228910724065033772133523230370773849709948530 89450777507879083442634420291861180736024127002634265953304576

        Assuming 24-bit color, there are 640 * 480 * 2**24 possible bit maps. That's 5.15e12.

        To put that number in perspective, if you could generate 1/second, it would take you 163,319 years.

        Now let's say you secured the services of 163,319 computers for 1 year and generated them all. It would require ~5 million million million million GB of storage to hold. So, let's say that the disks/tapes were available.

        Now to find that perfect picture that you are going to take of your great Aunt 5 years from now, all you've got to do is wade through all the mostly black and mostly white and mostly blue and mostly grey, and all those where you chopped off her head.

        If you can reject 1 per second that's gonna take you...

        Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
        Lingua non convalesco, consenesco et abolesco. -- Rule 1 has a caveat! -- Who broke the cabal?
        "Science is about questioning the status quo. Questioning authority".
        The "good enough" maybe good enough for the now, and perfection maybe unobtainable, but that should not preclude us from striving for perfection, when time, circumstance or desire allow.
        Check out the story The Library of Babel for a fictional universe in which such an experiment has been carried out with text.

        There are 5,153,960,755,200 (640*480*(2^24)) true colour 640x480 images.

        The file size of each image would be 921,654 (54 + 640*480*3) bytes.

        The disk space used by each image (on NTFS) would be 925,696 (ceil(921,654/4,096)*4,096) bytes (plus space used by the directory).

        The disk space used by all images (on NTFS) would be 4,771,000,855,245,619,200 (925,696 * 5,153,960,755,200) bytes (slightly under 5 billion Gigabytes).


        What if you generated 128x128 images using 16 colours?

        Num images = 160,000 File size = 8,310 bytes Disk space per images = 12,288 bytes Total disk space = 1,966,080,000 bytes =~ 2GB

        That's attainable, but it's only thumbnail size.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://480857]
and dust plays in a shaft of sunlight...

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (5)
As of 2017-03-30 23:00 GMT
Find Nodes?
    Voting Booth?
    Should Pluto Get Its Planethood Back?

    Results (364 votes). Check out past polls.