+ 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

24th Mar 2020, 10:22 AM
Monkey D. Luffy
Monkey D. Luffy - avatar
11 odpowiedzi
+ 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.
24th Mar 2020, 11:09 AM
Arsenic
Arsenic - avatar
24th Mar 2020, 12:53 PM
Oma Falk
Oma Falk - avatar
+ 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.
24th Mar 2020, 11:02 AM
🇮🇳Omkar🕉
🇮🇳Omkar🕉 - avatar
+ 4
LLLRUUD shortens to LU and leads to - 1 1
24th Mar 2020, 11:09 AM
Oma Falk
Oma Falk - avatar
+ 4
Oh thanks i interpreted LLLRUUD as LRUD and thus arrived at 0,0 Thanks Guys Arsenic Oma Falk 🇮🇳Omkar🕉.isActive = ![ ];
24th Mar 2020, 11:18 AM
Monkey D. Luffy
Monkey D. Luffy - avatar
+ 4
Aaditay Garg I figured that out after looking at your code🧐🙂🙃
24th Mar 2020, 11:21 AM
Arsenic
Arsenic - avatar
+ 3
🇮🇳Omkar🕉.isActive = ![ ]; Wow! thanks for finding that loophole And fixing it out also
24th Mar 2020, 11:24 AM
Monkey D. Luffy
Monkey D. Luffy - avatar
+ 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👨🏼‍💻👍
24th Mar 2020, 12:01 PM
Arsenic
Arsenic - avatar
+ 2
Arsenic i interpreted the SAME AXIS as SAME Direction
24th Mar 2020, 11:20 AM
Monkey D. Luffy
Monkey D. Luffy - avatar
+ 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 ? 🤞
24th Mar 2020, 11:49 AM
Monkey D. Luffy
Monkey D. Luffy - avatar
+ 2
Thanks Arsenic I understood it well thanks Oma Falk , Wonderful Community 😎
24th Mar 2020, 1:13 PM
Monkey D. Luffy
Monkey D. Luffy - avatar