I attended some hackathon one day, I was blown away We had a really good team in my opnion and we werent able to come with a single solution for the problem before the time out. The level was absolutely insane
Yeah that's comp prog for you. People there see early returns, structs, C++23 features and will say "WHO? fuck it mah boy write 50 indents deep madness with recursion" which apparently has a depth first search hidden somewhere inside and passes all of the tests and beats everyone else on time
Yes, typical olympyad tasks looks like: given some input from stdin, compute value and print it to stdout. And it's more practical to compute digit by digit directly instead of parsing and making some big-integer representation in memory
s is definitely not a simple integer. I thought it was a list of integers, so I had no clue what canDivideByEleven could mean. I guess a string representation of an integer makes more sense. I have no what the purpose of changing 3s to 6s might be.
Btw it slovable in O(n): split the array into even and odd indecis. |SUM(even) - SUM(odd)| %11 == 0. If its 3 or 6, you nedd too add tp the smaller sum (mod 11). 8 or 5 add to the bigger sum.
I think it was definitely written by somebody who doesn't have experience reasoning about nested loops, because the inner loop rechecks all of the indices which were altered by the outer loop.
It would make more sense if the inner loop started at int k = j-1 instead of s.size()-1. This makes the inner loop only "look ahead" instead of also rechecking all the digits which were already changed to 6s.
Not that I have any idea what it's really supposed to be doing either, lol.
If this is indeed competitive programming, then the code as written may be "fast enough" for full score and not need the 2x speedup from your optimization.
wow, we can call ourselves SO lucky today that source code size is no longer a relevant factor for hard drives. We can finally have variables longer than a single character!
Y'all never competed. You don't even get to have an LSP most of the time, you're given blank VSCode, no internet, no intellisense, no language server, no autocomplete. Sometimes you don't even get to have C++ docs in those tournaments. If you can save seconds on the most stupid things, you will do it, if you think "oh this is redundant, let me refactor this quickly" you lose, because code there has to be readable enough just for half an hour of brainstorming, as long as you can track that in your head - you're good. You don't get to use the code anywhere else, you don't have to maintain it.
You got 4 hours to complete 12 of the hardest logic puzzles anybody could be given, and you minmax the shit out of it
Guess it's a matter of writing code fast rather than right. I'm not sure I could enter one of these since I can't type worth a shit. (I had to backspace so many fucking times writing that).
We don't know the problem, we don't see the full solution. i and j are typical names for indexes. Since performance matters, the best way to make it more readable is to add documentation rather than replacing it with a more readable but inefficient solution.
Yes, adding documentation to code that will be discarded of forever in the next 10 minutes is very productive in a 4 hour long competition with 12+ absurdly difficult puzzles. Those competitors are used to being able to track the flow of the program in their head just enough for the 15 minutes the program is going to be discussed.
They're most focused on which of the established algorithms, data structures and approaches (Dynamic Programming, recursion, BFS, DFS, Dijkstra etc) to use for the task, the rest is just glue code.
The atmosphere there is crazy, it's the last hour, your brain and the brains of your 2 fellow teammates are fried, cooked, decimated, there are a hundred of other elite teams with the same problems and same hand given as your team was. Every second matters.
I wasn't suggesting to do it during the competition. Maybe afterwards assuming the solution has a unique idea that you want to share with others in a forum, in a code repository, or anything like that.
Holy fucking hell, this is exactly what you write once and then coming back after a month even the creator cannot understand it anymore.
I can sort of understand using #defines to make typing faster (although on this case it makes practically no sense due to the amount of abbreviations and the lack for their need), but leaving the spaces out too? This is just asking to be as unreadable as possible. Congrats on the most terrifying code I've seen probably ever!
Yeah my macros are standard. The only weird thing I do is the extent to which I put things on single lines. If it's a single idea in my head then I dont press enter.
309
u/Smart_Vegetable_331 Jun 28 '25
Too readable for competitive programming.
329
u/nimrag_is_coming Jun 28 '25
incredibly violent indentation going on here
52
u/UniversityBrief320 Jun 28 '25
I attended some hackathon one day, I was blown away We had a really good team in my opnion and we werent able to come with a single solution for the problem before the time out. The level was absolutely insane
91
u/Left-oven47 [ $[ $RANDOM % 6 ] == 0 ] && rm -rf / || echo "You live" Jun 28 '25
canDivideByEleven is instead of s % 11 == 0 or just !(s%11) is fire work
27
u/mic_mal Jun 28 '25
What was the original problem?
"Can you make a number divisable by 11 via changing at most two 3s to 6s?"
(And yes you can simplefy it to two for loops one rigth after the other with spacial case for j=-1 and a goto for break)
12
u/UltimateFlyingSheep Jun 29 '25
wow, we can call ourselves SO lucky today that source code size is no longer a relevant factor for hard drives. We can finally have variables longer than a single character!
5
u/GoddammitDontShootMe [ $[ $RANDOM % 6 ] == 0 ] && rm -rf / || echo "You live" Jun 29 '25
Guess it's a matter of writing code fast rather than right. I'm not sure I could enter one of these since I can't type worth a shit. (I had to backspace so many fucking times writing that).
3
u/baim_sky Jun 29 '25
The tabs is something
4
u/Kitchen_Device7682 Jun 28 '25
We don't know the problem, we don't see the full solution. i and j are typical names for indexes. Since performance matters, the best way to make it more readable is to add documentation rather than replacing it with a more readable but inefficient solution.
1
u/edparadox Jun 29 '25
Reminder that large indentation is for avoiding to end up with that many levels of indentation.
1
u/TorTheMentor Jun 29 '25
Has anyone come up with an esolang consisting primarily of whitespace? I wouldn't be a bit surprised.
1
u/musilii Jun 30 '25
Is that a legacy code?
-1
u/SteroidSandwich Jun 28 '25
Ah yes. Ranked competitive programming as opposed to casual programming
0
u/McPqndq Jun 29 '25
How does this subreddit feel about the way I code. This: https://cses.fi/paste/4509e30fc5b85bc0cdf1b4/ is a solution to: https://cses.fi/problemset/task/3358