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.

Filter by
Sorted by
Tagged with
2 votes
3 answers
103 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 ...
Tobias Grothe's user avatar
2 votes
2 answers
45 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 ...
JimmyHu's user avatar
  • 3,996
2 votes
1 answer
80 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 ...
Tobias Grothe's user avatar
3 votes
1 answer
89 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: ...
Riomare's user avatar
  • 31
0 votes
0 answers
20 views

matching generic items

Hello fellow developers I was wondering if anyone, with more understanding of javascript, is able to detect some potential flaws or performance issues with this recursive function. It works as ...
Lwtsde's user avatar
  • 1
2 votes
0 answers
34 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 ...
JimmyHu's user avatar
  • 3,996
4 votes
0 answers
123 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 ...
user266319's user avatar
1 vote
1 answer
78 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 ...
JimmyHu's user avatar
  • 3,996
3 votes
1 answer
59 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 ...
Roland Illig's user avatar
  • 21.2k
2 votes
1 answer
145 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 ...
Irwene's user avatar
  • 185
1 vote
1 answer
99 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 ...
JimmyHu's user avatar
  • 3,996
1 vote
1 answer
186 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 ...
Ramza's user avatar
  • 171
4 votes
2 answers
108 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 ...
BlazeRod11's user avatar
1 vote
0 answers
70 views

An Updated recursive_transform Template Function Implementation in C++

This is a follow-up question for A recursive_transform_view Template Function Implementation and A recursive_transform_view Template Function which returns a view in C++. In those implementations ...
JimmyHu's user avatar
  • 3,996
2 votes
1 answer
174 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 ...
driver's user avatar
  • 212
3 votes
1 answer
988 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 ...
driver's user avatar
  • 212
2 votes
1 answer
81 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 <...
JimmyHu's user avatar
  • 3,996
2 votes
1 answer
53 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 ...
JimmyHu's user avatar
  • 3,996
2 votes
0 answers
51 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 ...
JimmyHu's user avatar
  • 3,996
0 votes
0 answers
36 views

Recursively Tabulate All Folder Contents in Power Query

Background As discussed here on Stack Overflow, I am comparing a local and a OneDrive version of the same superfolder, in order to identify discrepancies in the sync. As such, I must compare all ...
Greg's user avatar
  • 359
1 vote
0 answers
74 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 ...
bluenote10's user avatar
1 vote
2 answers
83 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: ...
JimmyHu's user avatar
  • 3,996
4 votes
1 answer
321 views

tail recursive directory traversal in Rust

Please evaluate and help me understand if my attempted implementation of a tail recursive directory traversal function is actually tail recursive or not. I wrote this from my understanding that a tail ...
nohup's user avatar
  • 143
1 vote
1 answer
84 views

Test whether every element in an array is equal to sum of subsequent elements

I want to ask how to improve this code. Is it well-written or should anything be changed? Please let me know. And is it a bad thing to use arguments to store some info, such as the argument value here?...
mcccuklev's user avatar
  • 139
2 votes
1 answer
332 views

Find all permutations of string using recursion

Background: I am somewhat new to programming and only two weeks into learning Python. Currently trying to improve my understanding of recursion, which has been a tough concept for me to implement. ...
b-mitch's user avatar
  • 21
1 vote
0 answers
64 views

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

This is a follow-up question for A recursive_sum Template Function Implementation with Unwrap Level in C++ and A recursive_reduce_all Template Function ...
JimmyHu's user avatar
  • 3,996
2 votes
1 answer
139 views

A recursive_reduce_all Template Function Implementation in C++

This is a follow-up question for A recursive_sum Template Function Implementation with Unwrap Level in C++ and A recursive_unwrap_type_t Struct Implementation in C++. Considering the answer provided ...
JimmyHu's user avatar
  • 3,996
1 vote
0 answers
70 views

A recursive_unwrap_type_t Struct Implementation in C++

This is a follow-up question for A recursive_sum Template Function Implementation with Unwrap Level in C++. As G. Sliepen's answer mentioned, I am trying to implement a recursive struct for retrieve ...
JimmyHu's user avatar
  • 3,996
6 votes
3 answers
569 views

Recursive function for creating a cookies string

I've created the following function that creates a cookie string for passing to cURL. It can take a nested array or object of key-value pairs. It can either create nested cookie values as JSON, or ...
Jodes's user avatar
  • 340
0 votes
0 answers
33 views

Are there any implications of calling the same function recursively within a switchMap operator in RxJS?

In the code below, startFlow$ function that takes an input request object and subscribes to open a dialog/popup that performs a certain operation. Once the popup is ...
Chek Wei Tan's user avatar
2 votes
1 answer
121 views

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

This is a follow-up question for A Summation Function For Various Type Arbitrary Nested Iterable Implementation in C++ and A recursive_transform_view Template Function Implementation. In the previous ...
JimmyHu's user avatar
  • 3,996
2 votes
3 answers
474 views

Recursive palindrome check

I'm trying to solve this which basically calls for a recursive palindrome check with some minor extra steps (Special characters and whitespace can be ignored). The test inputs' length can be 100000 ...
YaMiN's user avatar
  • 125
5 votes
1 answer
135 views

Ackermann-Péter function call count using Writer monad

I'm quite new to Monads and I tried add function call counting to the Ackermann function code. The goal was simplicity, not performance. I want to have code review on the ...
Arpad Horvath's user avatar
0 votes
1 answer
98 views

The usages of make_view Template Function in C++

This is a follow-up question for A recursive_transform_view Template Function which returns a view in C++. I am trying to revise the structure of recursive_transform...
JimmyHu's user avatar
  • 3,996
2 votes
2 answers
126 views

A recursive_transform_view Template Function which returns a view in C++

This is a follow-up question for A recursive_transform_view Template Function Implementation. Following the suggestions mentioned in G. Sliepen's answer: Of course, it might be interesting in itself ...
JimmyHu's user avatar
  • 3,996
3 votes
2 answers
143 views

A recursive_transform_view Template Function Implementation

This is a follow-up question for A recursive_transform Template Function with Unwrap Level for std::array Implementation in C++. Considering the suggestion mentioned in Davislor's answer, I am trying ...
JimmyHu's user avatar
  • 3,996
3 votes
2 answers
199 views

A recursive_transform Template Function with Unwrap Level for std::array Implementation in C++

This is a follow-up question for A recursive_transform Template Function with Unwrap Level for Various Type Arbitrary Nested Iterable Implementation in C++. I am following the suggestions proposed by ...
JimmyHu's user avatar
  • 3,996
2 votes
2 answers
191 views

Generate the number of partitions of each integer

I've coded a program that calculates the number of partitions of n into at least two distinct parts, and is relatively quick too (about N^1.5 complexity). For input 30 000 it takes roughly 4 seconds. ...
svok's user avatar
  • 21
2 votes
1 answer
57 views

Merge Sort with Minimum Sufficient Variables, Verbosity and better Space Complexity

The majority of merge sort implementations searched online are provided with unnecessary variables and code lines. Here is an attempt to reduce that. However, does passing back the subArray as return ...
Thomas Mathew's user avatar
0 votes
1 answer
94 views

Printing Permutations

Following is a leetcode problem: Given an array nums of distinct integers, return all the possible permutations. You can return all the possible permutations. You can return the answer in any order. ...
Strange Alchemist's user avatar
0 votes
0 answers
75 views

Traversing a 2D array with a tree

In order to help me solve the December Jane Street puzzle "Die Agony" I wrote a quick and dirty script to manually brute-force through the thing and do the calculations for me. I then tried ...
Cirrocumulus's user avatar
5 votes
5 answers
555 views

Find the 10 largest files in a directory tree

I've recently finished a small project intended to better understand C. The program will output the ten largest files found (recursively in the event of subdirectories) in a specified directory. I've ...
John Harrington's user avatar
0 votes
1 answer
65 views

Checking several strings against a n-depth list of lists and returning one if its values

The data structure I am working with is a list of lists that is created by parsing a file. The depth of the list can vary. The list can have n Strings before its child-value begins. My current example ...
Qohelet's user avatar
  • 151
3 votes
2 answers
235 views

"Sudo Mode" in VBA to Let UDFs Modify Workbook

Background I am working on a VBA paradigm for modifying the Excel environment from a UDF. I call this "sudo mode", and I leverage Application.Run() to ...
Greg's user avatar
  • 359
1 vote
0 answers
70 views

Traveling salesman (Dynamic Approach) retrieve path without losing on time complexity

It is difficult to find resources on above programming problem therefore I've decided to ask a question on this forum. Using memoization and dynamic programming we can obtain a code that gives \$O(2^N ...
Kacper's user avatar
  • 11
5 votes
2 answers
651 views

Recursively calculating powers by squaring

Consider the following function that implements optimised O(log n) exponentiation by squaring: ...
saxbophone's user avatar
3 votes
0 answers
121 views

Finding the number of possible paths in a cave system (Python)

I've finally come up with working solution for day 12 of AdventOfCode, where you have to find the number of possible paths in a cave system following a given set of rules (described below). My ...
Oleg Shevchenko's user avatar
7 votes
1 answer
619 views

Get all partitions of an array into k non-empty sub-arrays

I am writing a function that takes an array and an integer number and returns an array of all the partitions into subarrays (so an array of arrays of subarrays). The number of subarrays is exact the ...
Joji's user avatar
  • 315
1 vote
0 answers
199 views

Find shortest knight's path between two chessboard squares

My function is a solution to the Knight's Travails problem. It receives start and end point coordinates on a chess board, and must return the shortest path from start to end. ...
Miguel Gil's user avatar
3 votes
1 answer
117 views

Exceeded time limit on Trie search with Backtracking using Swift

I have been trying to solve Trie related problems over at leet code and came across this interesting problem 211. Design Add and Search Words Data Structure Here is the question for convenience: 211. ...
Shawn Frank's user avatar

1
2 3 4 5
23