[SOLVED] Logical error ! A Codechef Problem ! | Sololearn: Learn to code for FREE!

+4

[SOLVED] Logical error ! A Codechef Problem !

https://www.codechef.com/problems/GIFTSRC SEE this problem And see the second rest case and third also What do you think about that , i think the second test case must give out 0,0 But i wonder how it is outputting -1 1 according to Codechef Here's My Try https://code.sololearn.com/cv9jq8y0y1eN/?ref=app I wanna You to explain me how the second and third test case over there gone that way

3/24/2020 10:22:21 AM

Monkey D. Luffy

11 Answers

New Answer

+5

Aaditay Garg read the problem carefully. It says that if consecutive moves are along SAME AXIS then it will not move which means LLRRU will only be treated as as LU.

+6

https://code.sololearn.com/c9t3fyiP2Xxx/?ref=app

+4

Check line 31 : ``` if moves[i] == moves[i-1] : ``` I think you were trying to check whether a charecter is equal to charecter preceding it. range(len(moves)) will generate iterable with elements starting from 0 upto len(moves)-1 so during first iteration counter `i` will be 0 and when you compare moves[i] with moves[i-1] you are comparing first element with last. (list[-1] gives last element of list) You can try using range(1,len(moves)). I don't know whether it works , that site requires me to create account for submitting code.

+4

LLLRUUD shortens to LU and leads to - 1 1

+4

Oh thanks i interpreted LLLRUUD as LRUD and thus arrived at 0,0 Thanks Guys Arsenic Oma Falk ๐Ÿ‡ฎ๐Ÿ‡ณOmkar๐Ÿ•‰.isActive = ![ ];

+4

Aaditay Garg I figured that out after looking at your code๐Ÿง๐Ÿ™‚๐Ÿ™ƒ

+3

๐Ÿ‡ฎ๐Ÿ‡ณOmkar๐Ÿ•‰.isActive = ![ ]; Wow! thanks for finding that loophole And fixing it out also

+3

Aaditay Garg I used C++ to solve this problem. But I think you will understand my logic behind it just by looking at the code only(do let me know if you don't understand it)๐Ÿ‘‡ https://code.sololearn.com/coRsaIEEzBGg/?ref=app EDIT:- now I have done commenting in the code to make it more understandable to you๐Ÿ‘จ๐Ÿผโ€๐Ÿ’ป๐Ÿ‘

+2

Arsenic i interpreted the SAME AXIS as SAME Direction

+2

Arsenic Oma Falk https://code.sololearn.com/cv9jq8y0y1eN/?ref=app This is what i have done to deal with SAME axis But this is not working, I don't think that Using ascii is ideal way to deal with this So , i wanna hear from you what way would you use to deal with same ? ๐Ÿคž

+2

Thanks Arsenic I understood it well thanks Oma Falk , Wonderful Community ๐Ÿ˜Ž