tirtha_raj's blog

By tirtha_raj, history, 20 months ago, In English

In today's contest(Problem C), I did a pretty silly mistake where I redeclared a variable inside a loop due to which the global variable was not getting updated. Hence I was trying to find the fault in my logic and Spent exactly 1 hour and 40 minutes regretting my life. While going through my solution now I discovered this and now I want to kill myself.

Now in all seriousness how do I stop repeating these silly errors in the heat of the contest? I have been doing these a lot lately.

  • Vote: I like it
  • +10
  • Vote: I do not like it

| Write comment?
»
20 months ago, # |
  Vote: I like it +6 Vote: I do not like it

I'd say just keep coding and facing these issues until they're gone. There used to be a time when I also was making way too many stupid mistakes like that and it's mostly over now. The thing is even if it happens few times then next time there is a better chance that you'll pay attention to such stuff when coding.

»
20 months ago, # |
  Vote: I like it 0 Vote: I do not like it

The same happens with me, but at least now we know what not to do. ¯_(ツ)_/¯

»
20 months ago, # |
  Vote: I like it +72 Vote: I do not like it

-Wshadow

»
20 months ago, # |
  Vote: I like it +14 Vote: I do not like it

Don't waste a lot of time, deleting and rewriting the solution can be a good option if you are confident that your approach is correct.

Debugging tools can also be helpful in identifying errors in the code, also using good names for your variable.

I have noticed that many people rely on print statements for debugging. But I believe that debugging tools are highly useful, but they seem to be underrated and rarely recommended, particularly in competitive programming.

  • »
    »
    20 months ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    I have "Debug Mode" in my environment which is pretty good to detect any compilation and runtime problems.

    P.S g++ -O3 -std=c++20 -Wall -Wextra -Wshadow -Wformat=2 -Wfloat-equal -Wconversion -Wlogical-op -Wshift-overflow=2 -Wduplicated-cond -Wcast-qual -Wcast-align -D_GLIBCXX_DEBUG -D_GLIBCXX_DEBUG_PEDANTIC -D_FORTIFY_SOURCE=2 -fsanitize=address -fsanitize=undefined -fsanitize=bounds -fno-sanitize-recover -fstack-protector

»
20 months ago, # |
  Vote: I like it 0 Vote: I do not like it

One very simple solution: name your variable in a distinct way. Also if you know how to debug, this mistake should be very noticeable.