Skip to main content
The 2025 Developer Survey results are in. Explore insights into technology and tools, careers, community and more. View results.

New answers tagged

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: ...
Rainer P.'s user avatar
  • 3,020
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 ...
G. Sliepen's user avatar
  • 68.2k
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 <...
J_H's user avatar
  • 40.8k
2 votes

backward induction algorithm computation

Your typehints are incorrect: current_reward etc. are np.ndarray (the actual runtime type), not ...
Reinderien's user avatar
  • 70.4k
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 ...
toolic's user avatar
  • 13.5k
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 ...
JimmyHu's user avatar
  • 7,096
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: ...
bruno's user avatar
  • 212
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-...
G. Sliepen's user avatar
  • 68.2k

Top 50 recent answers are included