[Community Puzzle] Decode the message

I have the same problem.
All my tests in the IDE pass but not the sixth test in the validators.

I think a test should be added in the IDE to be able to find the problem.

Iā€™ve sent the validator to both of you, can you tell me what was the problem ? Seems like itā€™s common to fail on it.

With Kotlin the test 6 and 7 failed for me as well. I identified a possible problem with both tests: The input P is to big for an (32 bit) integer and therefore it throws an exception on parsing it into an integer.

Iā€™ll might change my implementation today to use the Java BigInteger class or Long to store the input. But it makes the code more complex and it isnā€™t that ā€œeasyā€ (in terms of the difficulty shown) anymore.

By the way: I liked the puzzle. Gave me something to think and was very interesting :slight_smile:

It was asked to creator to fix the stub from int to long many times ā€¦
Looks like it is too complicated for him (or he doesnā€™t care) so i did it myself

Now itā€™s fine I finished the puzzle.

To explain you the problem I had I am gonna give you a simple example.
encoded = 974
alphabet = ā€œH_eo: Wrld!ā€

The length of the alphabet is 11. So what I do is:
974 / 11 * 11 = 968
6/ 11 = 0 (so index -1 and therefore an error)
6 / 1 = 6 (so index because itā€™s last element)

While the encoded message was built this way:
121 * 7 = 847
11 * (10 + 1) = 121
1 * 7 = 7 (6 because itā€™s the last element)

So when there is a string with a latest letter in the alphabet it was producing an error in some cases.

2 Likes

Thanks for the feeback, that offset by 1 was intended actually.
Iā€™ll swap the test and validator 6 so people have a chance to understand whatā€™s going on.

All test are OK except Validator 4.

Validator 4:

Input:

117
1234567890

Output:

811

Good luck!

After analysis, I think the problem encountered in test 6 is indeed a bug.
p = 34170657950616
c = ā€˜H_eo: Wrld!ā€™
result = 'Hello! World ā€™
In the system described, the last letter of the alphabet cannot be used by indicating the offset of the last character, otherwise the latter interferes with the following character (construction from right to left). We can correct this problem by using offset 0 for the last character, this does not stop the problem in the rest of the logic, we just have to deal with the case of offset 0 in the code (it must return the last character ). In this case the code must be 34170638463445 (which uses 0 for the ā€˜!ā€™) And not 34170657950616 (which uses 11)

1 Like

I donā€™t think is related to Cryptographyā€¦

Same here.
Thereā€™s a bug in test case 6, with
p=34170657950616 , c=ā€œH_eo: Wrld!ā€
iā€™m getting ā€œHello !WWorldā€.
And with p=34170638463445, as you mentioned, and with the same c iā€™m getting
ā€œHello ! Worldā€

No problem with the other test cases and validators.

Thereā€™s indeed a bugā€¦ but in your code.
The test canā€™t be ā€˜buggedā€™ since it consist as nothing more than the given input/output values. And more than 500 users (including me) have a fully working code, simply following whatā€™s said in the statement.
So you better read the statement again, and check back your codeā€¦

Hello,

The encoding scheme instructions are a bit unclear to me. I canā€™t tell if I am supposed to go through all combinations until Iā€™ve computed the guess at index p (test 1 seems to indicate this), or if it is some other encoding scheme that Iā€™ve gotten completely wrong (like dividing the number by alphabet size, and somehow ending up at the correct encoding)?

The instructions mention ā€œhelloā€ being encoded as 7073801. So I suspect it is because ā€œhelloā€ is the 7073801ā€™th combination with that alphabet?

Iā€™ve just begun here, but this is the first puzzle that has had me this stumped :joy:

Your interpretation of the ā€œhelloā€ example is correct. And while you can go through the combinations one by one to reach the answer, there are more efficient ways to calculate it.

Also, donā€™t assume there must be a single correct approach to a problem. There are often multiple ways :wink:

1 Like

It was described earlier (by @Null_A and @YuvalG), and claimed by @anon72424297 not to be a bug - but I still do not understand it: my code fails Test 6, but passes all else (including Validators). In any case, there is imbalance between test and validator, since Validator 6 is not covering the issue tested in Test 6.

  • Maybe someone can look to my published code and explain what detail I overlooked for Test 6?

Try running your code with C = ā€œH_eo: Wrld!ā€ (i.e. the same string as in Test 6), and P from 0 to 132. Youā€™ll notice that your code produces the wrong answer when P = 121 to P = 131 (and the answer becomes wrong again when P = 242 etc).

1 Like

Hah the same goes wrong with Test 3 C=ā€˜ABeDFCā€™ and P=36 (and further), or even C=ā€˜ABCā€™ and P=9 (in the latter, my code gives ā€˜ACAā€™ for P=9 while it should be ā€˜ACā€™. Iā€™d say that this is a pretty big mistake in my code that apparently is not covered in the Validators and only accidentally in Test 6. My code mishandles the final range of switching to an additional ā€˜digitā€™. I think my code counts similar to the numerical system 0ā€¦9 ā†’ 10 ā€¦ 99 ā†’ 100 ā€¦ 999 while it is required to count like 0 ā€¦9 ā†’ 00 ā€¦ 99 ā†’ 000 ā€¦ 999 for this contribution.

1 Like

Yes, thatā€™s exactly the issue :wink:

One of the approvers mentioned ā€œoff-by-one errorsā€ when they tried to solve the puzzle (and I assume thatā€™s the same issue you had faced earlier). While the approver was able to identify and fix the error in their own code, the author and the approver didnā€™t realise the need to include a case which could trigger such errors in a validator. What a pity.

Validator : All passed

Test : #6 Failed

[To comment from 2020, now, no french version available for this puzzle]

Fun problem, but nearly identical to Solid Integer!