Not Sure What Is Wrong With My Solution For 264

Back to General discussions forum

Vadim Pelyushenko     2022-03-09 02:10:27
User avatar

Ultimately it gave the wrong answer for the last test case: ULVYWZXGRCSMDEFBJHIKNTOPQA 41814627759

Expected was ULUYUZVGRCSMDDDBJGGJDSKKPA, but my program produced ULUYUYUGRCRLDEDBJHEEBRFDCU

But... I don't even see how the answer I produced was wrong. For the last present in the wishlist, there are 26 possibilities, and the choice for each character in the wishlist is independent of the others (I believe), and 41814627759 % 26 = 21, U is the 21st letter of the alphabet... so how could the answer possibly have 'A' as the last character?

zelevin     2022-03-09 02:36:17

[...]KKPA is correct.

U is the 21st letter of the alphabet

Is it? :)

Is Z the 26th letter of the alphabet? If it is, would your expression (N % 26) ever return Z?

Perhaps it might be instructive to examine not what results in the last letter but what results in the sixth letter.

I can give a few more hints (there is also an issue with modular math). But the above might suffice.

Vadim Pelyushenko     2022-03-09 02:50:33
User avatar

Is Z the 26th letter of the alphabet? If it is, would your expression (N % 26) ever return Z?

Okay okay, you got me there. I gloss over the fact that my solution actually computes it zero-indexed, so I pass in 1 less than the original input. So really my program would end up doing 41814627758 % 26 = 20, and U is the 20th letter of the alphabet if A is the 0th. With that, Z is a possible result of such a calculation.

zelevin     2022-03-09 02:55:13

Great. Now all I suggest is checking the off-by-one discrepancy in the sixth letter. Feel free to display N % 26 at each iteration as well, so you can check that it is not, as a matter of fact, an invariant.

Vadim Pelyushenko     2022-03-09 03:11:07
User avatar

▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮ ▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮ ▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮ ▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮ ▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮

Hello reader of this forum thread. I've redacted what I've written here to not spoil you with the approach that I took for this problem.

Vadim Pelyushenko     2022-03-09 03:14:43
User avatar

Great. Now all I suggest is checking the off-by-one discrepancy in the sixth letter. Feel free to display N % 26 at each iteration as well, so you can check that it is not, as a matter of fact, an invariant.

My last comment was made before looking at this comment, pondering it

Vadim Pelyushenko     2022-03-09 03:19:16
User avatar

Feel free to display N % 26

To be clear, I wasn't saying that I'm treating things as a ▮▮▮▮▮▮▮▮▮▮▮▮▮▮(another redaction forum reader, sorry). N % 26 only matter for the last character, because there are 26 choices for the last character.

Now all I suggest is checking the off-by-one discrepancy in the sixth letter

I'm thinking about it right now, but at least off the top of my head, I don't see how there could be an off-by-one there, because I start computing the result from right to left. Earlier errors(which happen rightwards in the result string) would accumulate.

zelevin     2022-03-09 03:27:27

because I start computing the result from right to left.

That is very interesting.

zelevin     2022-03-09 03:35:17

Oh, also:

because there are 26 choices for the last character.

Are there?

Vadim Pelyushenko     2022-03-09 03:36:01
User avatar

That is very interesting

I'm not sure to interpret that as meaning it is an approach that differs from yours, or if it means that you are trying to tell me that I should be computing it from left to right.

zelevin     2022-03-09 03:38:17

I'm not sure to interpret that as meaning it is an approach that differs from yours, or if it means that you are trying to tell me that I should be computing it from left to right.

It is definitely one of these two.

To be less flippant: I'm merely trying to keep this open thread as vague as possible for the sake of everyone who is yet to solve this wonderful little problem.

Vadim Pelyushenko     2022-03-09 03:39:03
User avatar

Oh, also: "because there are 26 choices for the last character." Are there?

There are 26 presents. So the last child doesn't get any say in what present they get, because there's only one present left. So they could have wished for any of the 26 presents and they would have gotten the same thing in the end.

zelevin     2022-03-09 03:42:26

So they could have wished for any of the 26 presents and they would have gotten the same thing in the end.

This statement is incorrect.

Here's what the problem statement says:

We will also assume that every child is able to choose a present before the carousel stops. (It wouldn't be nice to leave any little children without a present!)

Here's my last hint for now: what present did the last child wish for?

Vadim Pelyushenko     2022-03-09 04:05:02
User avatar

My program works for all of the test-cases except the last one... which has a length of 26. I realize what it is about 26 that makes my program treat it differently, but with my current understanding of the problem (which is evidently wrong), I would believe that actually the length 26 case is the only case in which my program is correct, and all the other ones are wrong.

I've employed a hacky modification to the program that makes it work for sizes <= 26. Submitted it, and it passed.

I don't understand at all. I need to reevaluate a fundamental part of the problem. I'll go through smaller test cases with a brute-force program and think about why what I thought was in fact wrong.

zelevin     2022-03-09 04:08:03

Good luck!

The crucial statements are that (1) the carousel spins only once for each child; (2) it is given that every child got a present.

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