posted 15 years ago
I don't have the book in front of me...but...
I think they are talking about a "boat" that is three cells long somewhere in an array that is 10 cells long. The boat could be in position "0,1,2", "1,2,3", "2,3,4" etc., up to position "7,8,9". The trick here is you don't actually need all 10 cells, but only the three relevant ones where the boat "is".
You declare a three-cell array to hold the positions. You say you have this:
Array = 0, 1, 2
Values = 4,5,6
That means the boat is actually in position 4,5 and 6 in a 10-cell line.
When the user guesses "5", you search all the VALUES stored in the array, to see if a '5' is stored anywhere. It turns out there is, so you return a 'hit', and shrink your array. That would leave this:
Array = 0, 1
Values = 4,6
If the user then guesses "2", you again search the VALUES in the array. 2 is not there, so it's a miss.
I think you're getting the array index confused with the array values - and it's the latter we're searching for.
There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors