0

This is probably easy for you guys but I can't find the answer anywhere and my maths isn't quite up to answering it. It's obviously easy to work out the number of different states the array can have but the following I can't answer:-

Array of 256 numbers any of which can be of the value 0-255. The initial value of the array will be 0,0,0,0,0 ...... 0 If I start the array at 0,1,2,3,4 ...... 255, how many previous states would I be losing?

Bipman

Bipman
  • 5
  • 1
  • 1
    What's the question? What does it mean to start an array? Is the array a function of time? Do we know something about the rules under which it changes over time? – lulu Jul 19 '17 at 18:42
  • Sorry, what I mean is that the array will start at 0,1,2,3,4 ..... 255 and then after running a function it will 'increase' by 1 i.e. the next state would be 0,1,2,3,4 ..... 255,0 i.e. the array is base 256 and will be increased by 1 each time. So if I start at 0,1,2,3,4 .... 255 instead of 0, how many counts before this will be lost? Hope that makes a bit more sense. – Bipman Jul 19 '17 at 18:48
  • It would've been clearer to say the array is a 2048 bit number (8*256). – Χpẘ Jul 19 '17 at 18:51
  • True indeed :-) – Bipman Jul 19 '17 at 18:58

3 Answers3

2

Perhaps another way to think about this is that we can put an ordering to all possible arrays and then ask the question ``Where does our desired array appear on the list?"

For example, one way you could answer this is by assuming $$ \begin{align*} A_0 &= [0,0,0,\cdots,0,0,0]\\ A_1 &= [0,0,0,\cdots,0,0,1]\\ A_2 &= [0,0,0,\cdots,0,0,2]\\ &\vdots\\ A_{255} &= [0,0,0,\cdots,0,0,255]\\ A_{256} &= [0,0,0,\cdots,0,1,0]\\ A_{257} &= [0,0,0,\cdots,0,1,1]\\ &\vdots\\ A_n &= [0,1,2,\cdots,253,254,255]. \end{align*} $$ Then the subscript $n$ will tell you how many arrays came before it in the ordering. Observe that for $$A_n=[a_{255},a_{254},a_{253},\cdots,a_2,a_1,a_0]\\=[0,1,2,\cdots,253,254,255]$$ we should have that $$ n=\sum_{k=0}^{255} a_k \cdot 256^k. $$

Laars Helenius
  • 7,965
  • 1
  • 23
  • 35
0

Assuming array is actually a 2048 bit number (which OP confirmed in comments):

You will lose all the states prior to starting value, which is 0x000102...FDFEFF states (since the number of states is 1 + starting value). In general you will lose the number of states equal to the starting value (assuming you consider the starting value as one of your states). So in the case of 0x0000...0000 you lose 0 states, and in the case 0xFFFF...FFFF you lose all but 1 state.

Χpẘ
  • 1,130
  • 6
  • 8
0

Interpreting $[0,1,2,\ldots,254,255]$ as a base-$256$ number, most significant digit first, the numeric value represented is $$ S = \sum_{k=0}^{255} (255 - k) 256^k $$ using the usual notation in which the "zeroth" term is the least significant digit and the $255$th term is the most significant. But if we add up the values of the "digits" of $[0,1,2,\cdots,254,255]$ from left to right instead of right to left, we find that $$ S = \sum_{m=0}^{255} m 256^{255 - m} = 256^{255} \sum_{m=0}^{255} m 256^{-m}. $$ This is a finite arithmetico-geometric series. There is a standard formula for its sum, but it's easy enough to use the derivation of the formula to find the sum. We know that $$ 256^{-255} S = \sum_{m=0}^{255} m 256^{-m}. $$

Then \begin{align} 256^{-256} S &= \frac{1}{256} \sum_{m=0}^{255} m 256^{-m} = \sum_{m=1}^{256} (m - 1) 256^{-m}, \\ 255 \cdot 256^{-256} S &= \left(256^{-255} - 256^{-256}\right)S \\ &= \sum_{m=0}^{255} m 256^{-m} - \sum_{m=1}^{256} (m - 1) 256^{- m} \\ &= 1\cdot 256^{-1} + 2 \cdot 256^{-2} + 3 \cdot 256^{-2} + \cdots + 255 \cdot 256^{-255} \\ &\phantom{= 1\cdot 256^{-1}\ } - 1 \cdot 256^{-2} - 2 \cdot 256^{-3} - \cdots - 254 \cdot 256^{-255} - 255 \cdot 256^{-256} \\ &= 1\cdot 256^{-1} + 1 \cdot 256^{-2} + 1 \cdot 256^{-2} + \cdots + \phantom{25}1\cdot 256^{-255} + 255 \cdot 256^{-256} \\ &= \sum_{m=1}^{255} 256^{-m} - 255 \cdot 256^{-256} \\ &= 256^{-1}\frac{1 - 256^{-255}}{1 - 256^{-1}} - 255 \cdot 256^{-256}, \end{align} and therefore $$ S = 256 \frac{256^{255} - 1}{255^2} - 1. $$

This is the number of "states" (integers base $256$) that come before $[0,1,2,\ldots,254,255].$ It's not quite one percent greater than $256^{254}$ (which is the value of the digit $1$ in $[0,1,2,\ldots,254,255]$).

David K
  • 98,388