lionelhill
Technical User
I can't claim authorship of this classic, but just in case anyone here hasn't seen it:
You are writing a piece of software that must fill an array. You are passed a pointer into the array somewhere, but you don't know where. The ends of the array are marked by dummy values that you will recognise when you meet them.
You can therefore fill the array by dealing with successive elements in it, spreading out from where you are. Sometimes you may wish to spread backwards, sometimes forwards, but you will always have to spread one element at once, because if you jump, you may jump over the end.
If the array is 8 elements long (plus its two dummy end values which you can ignore), in how many different orders could the array be filled (given all possible starting points and all possible sequences of filling the array in any combination of forward and backward steps)?
You are writing a piece of software that must fill an array. You are passed a pointer into the array somewhere, but you don't know where. The ends of the array are marked by dummy values that you will recognise when you meet them.
You can therefore fill the array by dealing with successive elements in it, spreading out from where you are. Sometimes you may wish to spread backwards, sometimes forwards, but you will always have to spread one element at once, because if you jump, you may jump over the end.
If the array is 8 elements long (plus its two dummy end values which you can ignore), in how many different orders could the array be filled (given all possible starting points and all possible sequences of filling the array in any combination of forward and backward steps)?