Sliding Window Search

Back to General discussions forum

simonhugo     2023-04-06 11:10:37
User avatar

Hello I just don't understand the statement. If I read the file and look for the text from the indicated positions I get (taking the first 15 bytes):

  • 22255 -> 'kable, save tha'
  • 22947 -> 'led to listen t'

Why is the first substring to search for "kable" (5 characters) and instead the second is "led to listen" (13 characters)? Do you have to stop when finding a punctuation character, should they be whole words?

In other positions I find a new line. what is taken as a substring for example for position 13155? And in those that begin with space? And those that start in the middle of a word?

  • 36587 -> 'd of myself in '
  • 9700 -> ' hoofs and
  • thank you
  • 31780 -> 'and actor, even a'
  • 21915 -> 'Lodge. It is a'
  • 4676 -> 'her notice, bu'
  • 25611 -> 'came a neat li'
  • 34708 -> 'ok sides with o'
  • 13155 -> 'n."

"I was a' * 7630 -> ' before one ha' * 46121 -> 'illusion."

'on' * 20855 -> 'amazing powers'

gardengnome     2023-04-06 12:18:17
User avatar

Take the second example: 22,947.

  1. "Preceeding match should be sought for only within the block of preceeding 4,096 bytes and the match of no more than 15 bytes is required." This means you are looking for the longest match in the preceeding 4,096 positions, but you don't have to match more than 15 characters.
  2. "Answer to each case should be 2-byte hexadecimal with its lowest 12 bits (or 3 digits) holding the offset and the highest 4 bits (one digit) storing the length"

So let's look at the expected answer 0x59A4.

  1. The highest digit is 5, i.e. a match of 5 characters.
  2. The 3 lower digits are 0x9A4, which translates to 2,468 as a decimal number. 22,947 - (2,468 + 1) = 20,478.

Text from position 22,947: led to listen ...

Text from position 20,478: led the most ...

simonhugo     2023-04-06 14:24:16
User avatar

Oh, okay. Thanks, it's already done.

Please login and solve 5 problems to be able to post at forum