A sample example for debugging code for newbs (like me)

Revision en1, by notsoawesome, 2024-08-25 00:14:27

This is something which I was happy to achieve on my own for 2004D - Colored Portals. I quickly achieved the greedy binary search, but I had few un-intended bugs (ideally would've saved time if I did a code review instead of debugging, but as a trade-off you do get a confidence that it will get resolved after debugging)

Here is the why this blog is for you:

  • You are newb like me.
  • You get frustrated when your code randomly gets WA and you don't know what the edge case/bug is there in your code.

Here is probably why this blog is not for you:

  • You are too good (please ignore, although, you can improvements are welcome!)
  • You probably know what to do, but just don't feel like debugging. (well, that's the only way I know which will work for sure for now)

Thing which helped the most:

Debug template — by Anshul_Johri

TL;DR of the debugger

  1. Write the most correct version you can think of for the solution (i.e via brute force)
  2. Compare them both — to check for wrong answers.
  3. Fix the bugs/edge cases.
  4. Voila!

The code for debugging

My Code

(feel free to suggest improvements which I am sure there will be as my main goal was to fix bugs and not improving my debugger code)

Tags helpful, guide, debugging

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en1 English notsoawesome 2024-08-25 00:14:27 10102 Initial revision (published)