Problem 141 description

Back to Problem Solutions forum

Moff     2014-08-07 11:28:35
User avatar

It seems to be wrong implementation of described algorithm.

If we use the example from description we have to pick the nearest find result in block:

an        20-2
d_        10-2
he to     58-5
l         19-1
d_         7-2
u          0-0

So the answer should be '2014 200A 503A 1013 2007 0000'.

But the checker accept another solution - we have to use the first find result from the very beginning of block:

an        20-2
d_        27-2
he to     58-5
l         38-1
d_        35-2
u          0-0

So the answer is '2014 201B 503A 1026 2023 0000'.

in the town where i was born live[d ]a man who saile[d ]to sea
                                  ^                  ^        
                                 27-2               10-2      

an[d ]he told us of his life in a land of submarines          
   ^                                                          `
substring

P.S. Sorry for my terrible English. My native language is C++.

Rodion (admin)     2014-08-07 11:59:24
User avatar

Oh, you are right - it is my mistake that checker searches from the wrong side.

I'm going to change its behaviour now - could you please do me a favor and test it once more?

I've added the line to problem statement:

If more than one prefix of the same length could be found, please choose the smallest offset.

UPD: I've updated the "example" at the bottom also.

nicolas_patrois     2014-08-07 12:58:00
User avatar

I think that I missed something.

I got this as test-cases:

40
22255 22947 36587 9700 31780 21915 4676 25611 34708 13155 7630 46121 20855                           

And I don’t know what length has to be tested.

Rodion (admin)     2014-08-07 13:22:47
User avatar

OMG, I'm extremely stupid today, I'm sorry. These awkward data appeared because after changing the checker I tested it myself and saved with predefined test data. %)

I'm quite sorry! Hope this is fixed now...

Moff     2014-08-07 14:58:21
User avatar

I've posted the second version successfully.

nicolas_patrois     2014-08-07 19:10:13
User avatar

I still don’t know what length has to be tried: why not 1, the only letter encountered at the given position? Is it the string "and he told "?

Guy Gervais     2014-08-07 21:51:48
User avatar

You have to find the best length between 1 and 15 (encoded as 1..F in the result). Once you find a letter that matches, check if the next one matches the second one from your original position. Then a 3rd and so on.

nicolas_patrois     2014-08-08 06:50:57
User avatar

OK, thank you. I did not understand that it was the best length that was needed.

Rodion (admin)     2014-08-08 07:30:47
User avatar

Nicolas and Serge - thanks for pointing this out - I'll try to improve the problem statement now!

nicolas_patrois     2014-08-08 14:12:38
User avatar

The offset should be calculated from Pi of from the position of the matching string? Does the "\n" count?

Actually, I find a longer match (7) for the first test case (22255) that is line 534 and the match is line 456.

Guy Gervais     2014-08-08 15:48:10
User avatar

You can only go back 4096 bytes from the search position (since you only have 3 hex bytes to encode the distance 000..FFF)

nicolas_patrois     2014-08-08 17:27:06
User avatar

My match is 3498 bytes before 22255.

Rodion (admin)     2014-08-08 18:25:33
User avatar

Hi! I'm sorry for being slow to answer.

Let's see. The file have substring kable, save that at position 22255. The answer given in the example refers to offset 215 (i.e. position 22039) - here is a single letter k.

>3498 bytes before 22255.

This places us somewhere at 18757 - here are words have that photograph - nothing like the substring we are searching for.

Probably it is worth checking that you did not convert file somehow (for example substituting CRLF with single LFs while reading or something like this). Hope this may help...

nicolas_patrois     2014-08-08 19:03:20
User avatar

I see "ave that ".

Ha, the substring must begin like the other one? OK, the second problem bring the answer.

Got it but there is still a bug in my code somewhere.

Rodion (admin)     2014-08-08 19:54:44
User avatar

Ah, thanks for explaining the cause of bewilderment! Seems I should add explanation of example to the problem statement!

Abhisek     2016-05-22 17:20:19

The byte string has to contain '\r'. So if you are using linux machine make sure you replace '\n' with '\r\n'

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