Skip to main content
5 votes

Form all possible well-formed strings of 'n' nested pairs of 2 types of ASCII brackets

size of test static const uint32_t N = 3; // number of pairs to gen for this run /* N = 5, count = ... Thank you kindly for those beautiful timing figures, I ...
J_H's user avatar
  • 32.4k
5 votes

Form all possible well-formed strings of 'n' nested pairs of 2 types of ASCII brackets

A hard-earned "senior's moment" (lasting longer than a moment), and a micro-optimisation... the "Doh!" I usually don't pay attention to effects like actual "time trial" ...
Fe2O3's user avatar
  • 1,917
4 votes

Chessboard configuartions with no possible capture on the next move

Naming things Your code is full of one-letter variables and variables with very short names. It makes it very hard to understand the code. Consider this line on its own: ...
G. Sliepen's user avatar
4 votes

Java code to delete all empty folders within a directory

The nio call Files.walkFileTree provides a much easier way to scan a directory tree using FileVisitor and has callbacks for each file and pre/post directory. All you need to do is setup and increment ...
DuncG's user avatar
  • 141
4 votes

Java code to delete all empty folders within a directory

You're using an actual logger - that's good. However, for the errors that appear in cleanupDirectory, it's probably a better idea to throw an exception. The caller ...
Reinderien's user avatar
  • 63.1k
4 votes

Pollard's rho algorithm implementation

I used std::multiset to determine how many times that factor appears It's an option. You could also use a plain old map to store a factor (key) and its exponent (...
user555045's user avatar
  • 10.3k
3 votes

Java code to delete all empty folders within a directory

You're not taking into account loops created by symbolic links. This may not be a problem to your use case but in a generic case it will lead to a stack overflow error. A quick but a bit dirty fix ...
TorbenPutkonen's user avatar
3 votes

Prevent stack memory usage for recursive function in C

Check the return value of malloc(): malloc() and family returns NULL to signify an error. ...
Harith's user avatar
  • 9,687
3 votes
Accepted

Double each occurrence of a char recursively

typo Wow, you really like that log10 expression. I see several occurrences of it. Might be worth packaging up in a helper function. Which you could unit test. I don't understand this expression at all:...
J_H's user avatar
  • 32.4k
3 votes

Solve the snake cube puzzle

To answer your question, you can avoid repetition by importing the names at the beginning of the file like so: import Dir.L import Dir.R ... I would also suggest ...
QuasiStellar's user avatar
  • 2,249
3 votes
Accepted

A recursive_replace_copy_if Template Function Implementation in C++

Try to use the same interface as std::ranges::replace_copy_if() Have a good look at how parameters are passed to ...
G. Sliepen's user avatar
3 votes
Accepted

Minimum number of basic operations to convert str1 into str2 - Levenshtein distance

Bug-1: According to the specification: Changes can only be made to string 1 and it is given that the sum of the lengths of the two strings does not exceed 25. Your buffers of 25 do not have any ...
Harith's user avatar
  • 9,687
3 votes
Accepted

Find largest sum not involving consecutive values

Do the math to fix a bug INT_MIN is not an appropriate value to return when the end of the array is reached (i >= N). It's ...
janos's user avatar
  • 111k
3 votes
Accepted

A recursive_flatten_view Template Function Implementation in C++

Copies everywhere I know that all unnecessary copy operations should be avoided, but I am not sure the way which I've done is correct. You haven't avoided unnecessary copies at all. In fact, you are ...
G. Sliepen's user avatar
3 votes
Accepted

Recursively iterate over every object in an object graph looking for specific types

I think the answer here is to just not use a yielding iterator because I don't really need to: ...
ScottishTapWater's user avatar
2 votes

Find largest sum not involving consecutive values

Algorithmically ... the two codes below achieve the same task No. if(i >= N){ return -1e15; } if(cache[i][j] != -1e18){ The "given&...
J_H's user avatar
  • 32.4k
2 votes

Constructing a dependency list recursively

design of Public API def get_down_deps( This is not a good identifier in a public context, though it could certainly be Fine as a _private helper. Public APIs ...
J_H's user avatar
  • 32.4k
2 votes
Accepted

Order guaranteed recursive_transform template function implementation with execution policy in C++

The mutexes inhibit parallel execution You use a mutex at each recursion level. This inhibits parallel execution of std::transform(). This defeats the purpose of ...
G. Sliepen's user avatar
2 votes

Given a string of letters, output all English words formable using only those letters

Overview The code layout is good, and you used meaningful names for classes, functions and variables. Lint check pylint identified a few issues. There are some long lines that can be shortened. You ...
toolic's user avatar
  • 4,385
2 votes
Accepted

Recursively load all navigation properties of an entity

Just focusing on the code structure at hand, the most obvious thing it that the following codeblock is basically repeated three times which violates DRY (Don't Repeat Yourself): ...
ChrisWue's user avatar
  • 20.3k
2 votes

Pentomino solver in Python

Kudos on tackling such an interesting problem! design of Public API ...
J_H's user avatar
  • 32.4k
2 votes

A recursive_minmax Template Function Implementation in C++

Bug You iterate the range twice, once for each partial result, which is forbidden for a simple std::ranges::input_range. You need at least a ...
Deduplicator's user avatar
  • 19.3k
2 votes

Prevent stack memory usage for recursive function in C

Clean-Up Use calloc() Where Appropriate You currently have: ...
Davislor's user avatar
  • 8,099
2 votes

Prevent stack memory usage for recursive function in C

Some side issues for OP. Deeper math issues Best to use float constants rather than double ones to initialize a ...
chux - Reinstate Monica's user avatar
2 votes

Recursive item recipe creation

Sorry I haven't gotten too deep into your code so my review will be a bit shallow. I like when by just looking at data structures, I can clearly understand the point. From looking at your structures I ...
K.H.'s user avatar
  • 2,678
2 votes
Accepted

recursive_invocable and recursive_project_invocable Concept Implementation in C++

Your code is correct, however it can be simplified in a number of ways: Unnecessary if-statements Whenever you see ...
G. Sliepen's user avatar
2 votes

Path Compression Algorithm in C#

Ok if I understand correctly you are trying to traverse a graph and compress any edges that contain an invisible node. I believe an improvement to your design is to have both a Node and an Edge class. ...
Henners2002's user avatar
2 votes
Accepted

A recursive_copy_if Template Function Implementation with Unwrap Level Implementation in C++

Range is not just an input range This is something I missed in my reviews of your previous questions. The parameter input is ...
G. Sliepen's user avatar
1 vote
Accepted

A recursive_find_if Template Function with Unwrap Level Implementation in C++

This looks fine, except that you indeed did not constrain Proj and UnaryPredicate, which will result in hard to read error ...
G. Sliepen's user avatar
1 vote
Accepted

recursive_any_of and recursive_none_of Template Functions Implementation in C++

This implementation is not short-circuiting The standard library's std::any_of() and std::none_of() are short-circuiting: they ...
G. Sliepen's user avatar

Only top scored, non community-wiki answers of a minimum length are eligible