New answers tagged algorithm
10
votes
Accepted
Golden-section optimization with complication
The crux is to write the code such that f appears only once in the method body.
This restriction appears pointless to me, but anyway. You can still write clean code if you incorporate three ideas:
...
9
votes
Golden-section optimization with complication
Avoid using sentinel values
J_H already mentioned magic numbers, and suggested replacing them with a constant. However, in this case using a sentinel value is really a bad idea. You have no idea what ...
3
votes
Golden-section optimization with complication
invariants
I wouldn't mind seeing an assert,
or at least an English sentence,
spelling out how x1, x2, & x3 are ordered.
And do we really need to introduce <...
2
votes
backward induction algorithm computation
Your typehints are incorrect: current_reward etc. are np.ndarray (the actual runtime type), not ...
2
votes
Tarjan's Strongly Connected Components finding algorithm
Please point out any ... code style issues.
Certainly.
Layout
The code could use some breathing space in terms of blank lines between functions.
The black program can be used to automatically ...
1
vote
N queen problem-like (+rooks and a different goal)
Try to avoid using namespace std;
using namespace std pollutes global namespace and leads to possible conflicts with other functions. Why is "using namespace ...
4
votes
N queen problem-like (+rooks and a different goal)
Why your program can be considered too slow by a 'judge' program
When I execute your program on my Pi 5 (Debian bookworm), because of these lines in your main:
...
7
votes
N queen problem-like (+rooks and a different goal)
The code is almost unreadable
I'm guessing this is one of the problems from a site like HackerRank or LeetCode, and the goal is to solve the problem in as little time as possible. However, single-...
Top 50 recent answers are included
Related Tags
algorithm × 5101java × 1285
python × 1206
performance × 1005
c++ × 851
programming-challenge × 660
javascript × 489
c# × 401
strings × 356
c × 334
python-3.x × 324
sorting × 320
beginner × 306
time-limit-exceeded × 253
graph × 253
array × 247
tree × 213
recursion × 177
interview-questions × 168
python-2.x × 163
complexity × 134
combinatorics × 133
mathematics × 110
c++11 × 102
matrix × 100