1

I want to create a text file or maybe a database? of all possible hex values between the following two hex values.

00251eb27d8d2deb15d615edd08dd7cf402638697a4aba6c7c199ce4ef858962
002526837f828960f7d3c1e8359eaea84e38183c7ab9345a663b474063ca9e20

the constraints are:

  • 64 digit hex values
  • fall in between the two numbers above only.
  • no more then 3 repeating same values.(eg. 777 is okay but 7777 is not.)

Can someone help me understand how many possibilities there would even be? Or help me understand if this is even a realistic option? I was thinking of using something like crunch to generate the text file output, but want to see if this is even realistic first and am having trouble figuring out how to do the math for it. I really would like to understand how to do the math to figure this out.

In order to figure out the math you can simplify the hex values however you need to in order to explain it.

8
  • The amount of different values between these numbers is around 10^58. This is a value that is at least one million times larger that the estimated number of atoms in earth (10^51). And the other constraints (no repeating sequences) do not really reduce this amount. No need to say that you cannot do that. Commented Jul 10, 2019 at 6:09
  • Thank you for your response. Can you please explain how you figured out 10^58? I'm curious about figuring out the math more than anything.
    – cigol on
    Commented Jul 10, 2019 at 7:11
  • 1
    You are absolutely right. Counting the digits gives the number of hex digits. Then a simple way to estimate the number of decimal digits, if a number has h hex digit, its number of decimal digits will be roughly d=h*6/5. This is based on the fact the 10^6~16^5(=1048576). Commented Jul 10, 2019 at 8:01
  • 1
    I double checked my computation with my calculator and indeed my result is wrong, as it was in hexadecimal. The number of different numbers in you range is ~10^70... (remember that the number of atoms in the known universe is estimated to 10^80). Commented Jul 10, 2019 at 8:08
  • 1
    @cigolon I added an answer with corrected values ... the estimate from hex (without repetitions constraints) is doable without bigint math just on strings mine has just slightly less than 2% error in it ...the repetition constraint is a whole different thing ...
    – Spektre
    Commented Jul 10, 2019 at 10:33

1 Answer 1

1
  1. all numbers rough estimate

    as Alain Merigot sugested you just count the number of digits from first change (from MSB to LSB):

    00251eb27d8d2deb15d615edd08dd7cf402638697a4aba6c7c199ce4ef858962h
    002526837f828960f7d3c1e8359eaea84e38183c7ab9345a663b474063ca9e20h
        |<---------------------60 digitis------------------------->|
    

    that gives us 16^60 possibilities. If you want decimals then conversion is done like this:

    dec_digits/hex_digits = log(16)/log(10) = 1.204119982655924780854955578898
    dec_digits = hex_digits * 1.204119982655924780854955578898
    dec_digits = 60 * 1.204119982655924780854955578898 = ~72.25
    

    as ratio between integer digits of any base is constant leading to 10^72.25 possibilities.

  2. all numbers precisely

    simply substract the 2 numbers so the result is non negative (its doable on strings with single for loop if you do not have bigints)

    -00251eb27d8d2deb15d615edd08dd7cf402638697a4aba6c7c199ce4ef858962h
    +002526837f828960f7d3c1e8359eaea84e38183c7ab9345a663b474063ca9e20h
    ------------------------------------------------------------------
     000007D101F55B75E1FDABFA6510D6D90E11DFD3006E79EDEA21AA5B744514BEh
    

    if I convert it to dec using this str_hex2dec the result is:

    53947059527385558921671339033187394318456441692296348428515181989270718 = 5.39*10^70
    

    we can also do an rough estimate from hex instead:

    000007D101F55B75E1FDABFA6510D6D90E11DFD3006E79EDEA21AA5B744514BEh
         ||<----------------------58 hex digits------------------->|
         |
         7h -> 0111b -> 3 bits
    

    so we got 59 hex digits each hex digits is 4 binary bits except the first which is 3 bits only giving us rough estimate (but much more precise than then in #1):

    3 + 58*4 = 235 bits -> 2^235 numbers
    

    again converting to decadic:

    235 * log(2)/log(10) = 70.74
    

    leading to estimate:

    10^70.74 = 10^0.74 * 10^70 = 5.4954*10^70
    

    which is pretty close to the real deal above.

  3. repeated digits constraint

    this one is complicated one. We need to substract the count of all the possible numbers with repetition of digits. That is probability math (not my strong suite) but you can approach it as like this:

    For example we got 58 hex digits. So how many consequent n=4 digits like 7777 we can have in there? If we put the 7777 from start to end that is digits-n = 58+1-4possible locations...

    For each location the resulting digits can have "any" combination so possibilities would multiply by the unused digits possibilities:

    (digits+1-n)*16^(digits-n)
    

    now the n = <4 , digits> so the possibilities cobined:

    (digits+1-4)*16^(digits+1-4) + (digits+1-5)*16^(digits-5) + (digits+1-6)*16^(digits-6) ... + 1
    (digits-3)*16^(digits-4) + (digits-4)*16^(digits-5) + (digits-5)*16^(digits-6) ... + 1
    

    Now the repetitive digit can be any from 0..F so the whole stuf multiplies by 16 too...

    (digits-3)*16^(digits-3) + (digits-4)*16^(digits-4) + (digits-5)*16^(digits-5) ... + 16
    

    again this is rough estimate not accounting for edge cases and duplicity (you know if there are 2 repetitions or more they are accounted more times instead of once, also neighboring digits to the repetitive sequence can not have the same digit value etc ... accounting for all cases exactly would lead to insane equations that would not differ too much form the rough estimate) so the resulting rough estimate would be:

    16^digits - sum[i=1,2,3,...,digits-3]( i*16^i )
    

Now the creation would be "simple" you just implement increment of an hex value in the string and test for validity (repetitions):

1. increment
2. test validity
3. if valid store result
4. if end still not reached goto 1

However the resulting data would be huge and computation power needed for this too ... so you would most likely dye of old age before finished not to mention fill up your storage long before that...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.