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
...
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" ...
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:
...
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 ...
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 ...
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 (...
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 ...
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. ...
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:...
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 ...
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 ...
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 ...
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 ...
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 ...
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:
...
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&...
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 ...
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 ...
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 ...
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):
...
2
votes
Pentomino solver in Python
Kudos on tackling such an interesting problem!
design of Public API
...
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 ...
2
votes
Prevent stack memory usage for recursive function in C
Clean-Up
Use calloc() Where Appropriate
You currently have:
...
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 ...
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 ...
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 ...
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.
...
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 ...
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 ...
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 ...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
recursion × 1136python × 244
java × 217
c++ × 186
algorithm × 179
performance × 158
javascript × 106
c# × 103
programming-challenge × 76
c++20 × 72
tree × 68
beginner × 67
python-3.x × 63
c × 59
strings × 49
combinatorics × 49
functional-programming × 47
template × 43
array × 42
haskell × 33
dynamic-programming × 33
constrained-templates × 31
file-system × 30
sorting × 27
time-limit-exceeded × 25