Questions tagged [recursion]
Recursion in computer science is a method of problem solving where the solution to a problem depends on solutions to smaller instances of the same problem.
1,131 questions
2
votes
1
answer
89
views
Return breakdown of component from database into its constituent materials; correctly handle recursive scenarios
I’m working with a MySQL database that models product compositions and raw materials. There are two relevant tables with columns as shown:
product_recipes:
...
2
votes
1
answer
149
views
F# - Recursively find the first available item in a range definition
I have the following EF Core table:
...
5
votes
3
answers
765
views
A simple checksum for java.math.BigInteger
Intro
I have a simple methods that converts the input instances of java.math.BigInteger to checksum. The checksum algorithm sums up all the digits in the input <...
2
votes
0
answers
80
views
A recursive_minmax Template Function with Unwrap Level Implementation
This is a follow-up question for A recursive_minmax Template Function Implementation in C++ and A recursive_flatten_view Template Function Implementation in C++. The ...
6
votes
1
answer
932
views
Python function that deeply "freezes" an object
I implemented a function that gets an object and returns its immutable counterpart. If the object contains another mutable object at any level, it freezes it too.
Is my code is good and/or can it be ...
5
votes
3
answers
1k
views
LeetCode 678: Valid Parenthesis String, Recursion memoization to DP
How can the following recursion + memoization code be converted into a tabulation format dynamic programming solution?
The code is working, but I want to improve it.
The challenge I am facing is ...
4
votes
2
answers
144
views
Advent of Code 2015 "Not Quite Lisp", in Common Lisp
I've been toying around with random programming languages for about 15 years. I'm just more of a sysadmin type than a programmer, but I've always wanted to do programming, so here I am. I know a bit ...
5
votes
2
answers
212
views
Is this Python decorator a good idea to solve circular recursion?
I have several model classes, let's say A_0, A_1, ..., A_N
I have a method A_0.to_A_1() that calls A_1.to_A_2(), ... that calls ..., that calls A_(N-1).to_A_N()
So far so good, but A_N may then call ...
5
votes
2
answers
151
views
Check whether two Strings are anagrams of each other - then print all anagrams
I should write a CLI through which two Strings can be read in. These two Strings should be checked for whether they are anagrams of each other
For both Strings, I should give out all their possible ...
2
votes
1
answer
263
views
Pollard's rho algorithm implementation
I used std::multiset to determine how many times that factor appears.
I'd like to know if it can be improved; I've focused on the algorithm rather than the code.
...
2
votes
0
answers
50
views
A recursive_replace_copy_if Template Function with Unwrap Level Implementation in C++
This is a follow-up question for A recursive_replace_copy_if Template Function Implementation in C++. I am trying to implement recursive_replace_copy_if template ...
9
votes
3
answers
679
views
Form all possible well-formed strings of 'n' nested pairs of 2 types of ASCII brackets
Taking an interest in the challenge presented in this recent Code Review question, I've concocted a C solution (valid as C++, if I'm not mistaken) seeking to reduce both the lines of code and the ...
3
votes
1
answer
137
views
Recursively iterate over every object in an object graph looking for specific types
I have an object graph which contains two types of objects that I care about:
Link objects that contain an ID and a reference to the object with that ID.
...
4
votes
1
answer
93
views
A recursive_flatten_view Template Function Implementation in C++
This is a follow-up question for A recursive_flatten Template Function Implementation in C++. I am trying to follow G. Sliepen's answer to create ...
3
votes
1
answer
117
views
A recursive_flatten Template Function Implementation in C++
This is a follow-up question for A Summation Function For Boost.MultiArray in C++, A recursive_minmax Template Function Implementation in C++ and A recursive_reduce_all Template Function ...
1
vote
1
answer
68
views
recursive_remove and recursive_remove_if Template Function with Unwrap Level Implementation in C++
This is a follow-up question for recursive_find and recursive_find_if_not Template Functions Implementation in C++ and A recursive_copy_if Template Function Implementation with Unwrap Level ...
4
votes
1
answer
130
views
A recursive_copy_if Template Function Implementation with Unwrap Level Implementation in C++
This is a follow-up question for A recursive_copy_if Template Function Implementation in C++ and recursive_invocable and recursive_project_invocable Concept Implementation in C++. I am trying to ...
1
vote
0
answers
68
views
An Updated recursive_transform_reduce Template Function with Unwrap Level Implementation in C++
This is a follow-up question for A recursive_transform_reduce Template Function with Unwrap Level Implementation in C++. To fix the issue mentioned in G. Sliepen's answer, I updated the test cases and ...
3
votes
1
answer
89
views
A recursive_transform_reduce Template Function with Unwrap Level Implementation in C++
This is a follow-up question for A recursive_transform_reduce Function for Various Type Arbitrary Nested Iterable Implementation in C++ and recursive_invocable and recursive_project_invocable Concept ...
2
votes
1
answer
100
views
recursive_find and recursive_find_if_not Template Functions Implementation in C++
This is a follow-up question for A recursive_find_if Template Function with Unwrap Level Implementation in C++ and recursive_invocable and recursive_project_invocable Concept Implementation in C++. I ...
1
vote
1
answer
148
views
Path Compression Algorithm in C#
Let's consider a simple graph represented by the following edges, where true indicates a visible node and false indicates a non-visible node:
...
2
votes
1
answer
92
views
recursive_invocable and recursive_project_invocable Concept Implementation in C++
This is a follow-up question for A recursive_find_if Template Function with Unwrap Level Implementation in C++. I am trying to make some constrains on Proj and <...
9
votes
3
answers
375
views
Java code to delete all empty folders within a directory
Given the path to a filesystem directory, the task is to delete all empty directories within that root directory. After the process is finished, no empty dir should exist under the root directory (the ...
2
votes
2
answers
110
views
A recursive_find_if Template Function with Unwrap Level Implementation in C++
This is a follow-up question for A recursive_find_if_all Template Function Implementation in C++, A recursive_all_of Template Function Implementation in C++ and A recursive_all_of Template Function ...
3
votes
1
answer
75
views
A recursive_all_of Template Function with Unwrap Level Implementation in C++
This is a follow-up question for A recursive_find_if_all Template Function Implementation in C++ and A recursive_all_of Template Function Implementation in C++. To support ...
1
vote
1
answer
99
views
A recursive_find_if_all Template Function Implementation in C++
This is a follow-up question for recursive_any_of and recursive_none_of Template Functions Implementation in C++. I am trying to follow the suggestion of G. Sliepen's answer to implement ...
1
vote
1
answer
85
views
recursive_any_of and recursive_none_of Template Functions Implementation in C++
This is a follow-up question for A recursive_all_of Template Function Implementation in C++ and A recursive_count_if Function For Various Type Arbitrary Nested Iterable Implementation in C++. Besides <...
2
votes
2
answers
131
views
A recursive_all_of Template Function Implementation in C++
This is a follow-up question for A recursive_foreach_all Template Function Implementation in C++. I am trying to implement recursive_all_of template function in ...
2
votes
3
answers
312
views
Prevent stack memory usage for recursive function in C
This C code does DBSCAN - Density-based spatial clustering of applications with noise. It's a cluster algorithm for turining unsupervised (no labels) data to become ...
3
votes
1
answer
84
views
Recursive item recipe creation
I was trying to write code that would get as input a recipe consisting of item materials and would create all possible recipes that could be used to create craftable of the recipe.
The Recipe is ...
6
votes
1
answer
74
views
Chessboard configuartions with no possible capture on the next move
THE TASK:
Given an NxM "chess"board and Q,R,B,K where Q is the number of queens, R the number of rooks, B the number of bishops, and K the number of knights find out how many possible ...
4
votes
3
answers
217
views
Redouble each occurrence of char recursively, and add n
In following of this question, I would like to have a second review.
The exercise is to write a recursive method that takes a String and a ...
3
votes
2
answers
317
views
A recursive_minmax Template Function Implementation in C++
This is a follow-up question for A Maximum Function For Various Type Arbitrary Nested Iterable Implementation in C++. Besides the function for finding maximum, I am trying to implement ...
3
votes
1
answer
116
views
Double each occurrence of a char recursively
The exercise is to write a recursive method that takes a String and a char parameter and returns a ...
3
votes
1
answer
208
views
Pentomino solver in Python
When I was a child, I used to play Ubongo board game, recently I discovered Pentomino puzzle and I wanted to create a custom solver in python for it. Here is what I got:
...
2
votes
1
answer
172
views
A recursive_fold_right_all Template Function Implementation in C++
This is a follow-up question for A recursive_fold_left_all Template Function Implementation in C++. Besides recursive_fold_left_all function, I am trying to ...
7
votes
1
answer
266
views
Find the longest "common sequence" in two lists
In short, the algorithm must find the longest sequence that joins together common sequences from two lists (a more formal specification is given in the code's header).
The lists are assumed to contain ...
2
votes
1
answer
127
views
An Updated recursive_reduce_string Template Function Implementation in C++
This is a follow-up question for A recursive_reduce Template Function with Unwrap Level Implementation in C++ and A recursive_reduce_string Template Function Implementation in C++. Considering the ...
4
votes
1
answer
120
views
Solve the snake cube puzzle
I wrote a solver for the snake cube puzzle. The solver can be easily adapted to arbitrary snakes.
Since the program takes only a few seconds to run, I didn't care to optimize for speed, instead I ...
3
votes
1
answer
891
views
Recursively load all navigation properties of an entity
I have a table representing a class hierarchy using the TPH model.
Some of those sub classes have navigation properties (collections and/or references).
I'm trying to preload them as I know I will ...
1
vote
1
answer
162
views
A recursive_reduce_string Template Function Implementation in C++
This is a follow-up question for A recursive_sum Template Function Implementation with Unwrap Level in C++, A recursive_reduce_all Template Function Implementation ...
2
votes
1
answer
815
views
Recursively create a TreeView for file paths using C# and WPF
I'm building a program that allows the user to monitor files on their local system. To display the files, I created a TreeView using ...
4
votes
2
answers
178
views
Find largest sum not involving consecutive values
There is a question to basically find the largest sum in an array, such that no two elements are chosen adjacent to each other. The concept is to recursively calculate the sum, while considering and ...
2
votes
1
answer
236
views
k-dice Ways to get a target value
I'm trying to solve the following problem:
You have a k-dice.
A k-dice is a dice which have k-faces and each face have value written from 1 to k.
Eg. A 6-dice is the normal dice we use while playing ...
3
votes
1
answer
1k
views
Knock down tall buildings
I'm trying to solve the following problem:
As you know Bob likes to destroy the buildings.
There are N buildings in a city, ith building has ai floors.
Bob can do the following operation.
Choose a ...
3
votes
1
answer
171
views
A recursive_foreach_all Template Function Implementation in C++
This is a follow-up question for A recursive_fold_left_all Template Function Implementation in C++. As mentioned in G. Sliepen's answer, I am trying to implement <...
2
votes
1
answer
116
views
A recursive_fold_left_all Template Function Implementation in C++
This is a follow-up question for A recursive_sum Template Function Implementation with Unwrap Level in C++. I am trying to implement a recursive version fold_left ...
3
votes
1
answer
110
views
A recursive_depth Function Implementation with Target Type Parameter in C++
This is a follow-up question for A recursive_depth function for calculating depth of nested types implementation in C++. I am rethinking about the proposed ...
1
vote
0
answers
131
views
Recursive macro in Rust to assemble a node tree
This is my first time writing a somewhat non-trivial declarative + recursive macro in Rust. I drew inspiration from this answer.
The goal is to come up with a recursive macro that allows to assemble ...
1
vote
2
answers
141
views
An arithmeticable Concept Implementation in C++
This is a follow-up question for A recursive_reduce_all Template Function Implementation in C++. As G. Sliepen's answer mentioned:
...