# [Community Puzzle] Auto pickup

https://www.codingame.com/training/medium/auto-pickup

Send your feedback or ask for help here!

Created by @vivax3794,validated by @IAmNoob,@Gevater_Tod4711 and @TBali.
If you have any issues, feel free to ping them.

Hello,

the input are:
line 1: the length of the packet
line 2: the packet to inspect

Perhaps there is a mistake for the test case 5? (line1 gives 48, but line2 len is 63).

2 Likes

Itâ€™s not a medium puzzle, itâ€™s an easy puzzle.

Indeed, I noticed that too and corrected it. Thanks for the observation.

It is an easy puzzle. Besides, line one to state the string length seems to be unnecessary.

Hi,

I was struggling with the 3rd validator and I think that the statement is somehow incomplete.

3rd validator input is: â€ś00100101110100011â€ť.
At first, my algorithm was detecting the first occurrence of â€ś101â€ť, so the one that starts at index 5.

Then, I realized it was not a â€śvalid packetâ€ť because then the length of the item id would be too large for the whole string.

So, from what I understand, that occurrence of â€ś101â€ť is discarded and we proceed to the next one, at index 9. That one is valid and that is how we get â€ś00100011â€ť as the answer.

I think that â€śinvalid packetâ€ť rule should be specified in the statement, unless I misunderstood something.

Plus, I donâ€™t understand how I am supposed to pass the last validator (â€śthat is a long oneâ€ť).
The input starts with â€ś100100111100001001001011001010100111011110[â€¦]â€ť
Again, from what I understand, the first packet can be found at index 20 and has a length of â€ś1001â€ť so the item id is â€ś010100111â€ť.
Therefore, I find that my first response packet is: â€ś0011001010100111â€ť.
But the validator is expecting the first packet to be: â€ś0010011101â€ťâ€¦
How can it be?

2 Likes

Your algorithm is incorrect, no matter you are detecting the first or second or third occurrence of â€ś101â€ť.

There are 3 bits used as opcode so that there are at most 8 different opcodes. Only two of them are defined. You should always follow the data format to read the opcode bits and then size bits and then the payload. When the opcode is undefined, discard the payload. When it is defined, follow instruction to process.

2 Likes

I see. So I should read the first 3 bits and follow the instructions only if these 3 bits are â€ś101â€ť?
Your answer is a little bit abstract to me and Iâ€™m not sure if I understood correctly.

EDIT: Oh, I think I figured out. Actually, no matter what the opcode is, itâ€™s always followed by 4 bits defining the packet length and then by [packet length] bits. And I just have to take the packet into account if the opcode is known (in my case, â€ś101â€ť). Thanks!

Hi,
How did you pass the last validator ? I understand your comment and totally donâ€™t understand why we are getting â€ś0010011101â€ť for the last validator. I donâ€™t understand how java_coffe-cupâ€™s answer helped you solve this problemâ€¦
Cheers !

Hi
What java_coffee_cup made me understand is that you do have to take each opcode into account, get its packet length and its packet info, no matter the opcode is defined or not (= no matter itâ€™s a â€ś101â€ť or not). Then, if itâ€™s indeed a â€ś101â€ť, you eventually do stuff. Finally, no matter the opcode was defined or not, you discard (i.e. â€śmove forward into the stringâ€ť) the entire payload (opcode + length + info).

For example, with 100.1001.111000010.010.0101.10010.101.0011.101.111.0
(I inserted dots manually for better understanding)
Idx. 0: â€ś100â€ť = opcode
Idx. 3: â€ś1001â€ť = length (= 9)
Idx. 7: â€ś111000010â€ť = info
"100" is an undefined opcode so I donâ€™t do anything
Idx. 16: â€ś010â€ť = opcode
Idx. 19: â€ś0101â€ť = length (= 5)
Idx. 23: â€ś10010â€ť = info
"010" is an undefined opcode so I donâ€™t do anything
Idx. 28: â€ś101â€ť = opcode
Idx. 31: â€ś0011â€ť = length (= 3)
Idx. 35: â€ś101â€ť = info
"101" is a defined opcode so I print â€ś001{length}{info}â€ť = "0010011101"

Etcâ€¦
Does it help?

4 Likes

Hi,
Yep, understand it now ! Managed to get 100% thanks to your help, so thank you very much !
Cheers

1 Like

Honestly, this puzzle brings nothing. Once you sort out the obfuscating statement, the task to do is: