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
0
votes
1answer
26 views

extents_to_array and array_to_extents functions for Boost.MultiArray in C++

This is a follow-up question for A get_extents helper function for Boost.MultiArray in C++. In order to retrieve, manipulate and calculate size information in each dimension from Boost.MultiArray in ...
3
votes
0answers
52 views

Lisp expression parser

I'm building a very simple Lisp interpreter. Similar to the the one from here. Here is what I have so far for the parsing part, that is, everything from "text is passed to the the program" ...
0
votes
0answers
32 views

Enumerating all fixed-length paths from a vertex in a graph

Enumerating all fixed-length paths from a vertex in a graph 1. Graph-related classes Base implementations of the relevant classes in my graph library. I'm using C#9 in a .NET 5 project. I opted to use ...
3
votes
0answers
35 views

A recursive_transform Template Function with Unwrap Level for Various Type Arbitrary Nested Iterable Implementation in C++

This is a follow-up question for A recursive_transform Template Function Implementation with std::invocable concept in C++ and A recursive_transform Template Function Implementation with ...
0
votes
0answers
31 views

A batch_recursive_count_if Function with Unwrap Level for Various Type Arbitrary Nested Iterable Implementation in C++

This is a follow-up question for A recursive_count_if Function For Various Type Arbitrary Nested Iterable Implementation in C++ and A recursive_count_if Function with Unwrap Level for Various Type ...
0
votes
0answers
40 views

Efficiently calculate value of Pascal's Triangle using memoization and recursion(updated)

Follow up to Efficiently calculate value of Pascal's Triangle using memoization and recursion Based on feedback given by jvwh in the answers ...
2
votes
1answer
56 views

Recursive type checking for containers

This code checks the type, length and depth (highest number of nested containers) of the container as well as the type of its sub-containers and its elements. There are also two simple methods for ...
3
votes
1answer
48 views

Efficiently calculate value of Pascal's Triangle using memoization and recursion

So reading about functional programming, applications to dynamic programming, and learning Scala. I figured I would try it out with a popular example, Pascal's Triangle, tests against known values ...
0
votes
2answers
61 views

A recursive function to reverse string

Write a recursive version of the function reverse(s), which reverses the string s in place. I'm studying K&R and wrote a code for the question. ...
1
vote
1answer
48 views

String tokenizer

Objective: Create a function called wordsAndSpaces that splits a string on groups of spaces, preserving each group of space characters as a single token. Example: <...
1
vote
1answer
43 views

Maintaining state while walking a tree structure

The following code creates a simple tree structure and then walks through the tree looking for node with the value 9 that appears after we have seen a node with the value 1 and a node with the value 4 ...
2
votes
1answer
62 views

Pokemon Soul Link tracker

I've just finished writing a program to help track Pokemon across Soul Links. The goal of the program is to take in the names of the two Pokemon alongside the route that they were caught on. The ...
2
votes
1answer
74 views

C++17 Recursive Fibonacci calculation with memoization

Compiler is g++ 4.2. I'm new to C++, but I've done a lot of data science, web scraping, and some socketing stuff in Python. This code generates the nth Fibonacci number, either with a naive ...
2
votes
2answers
161 views

Downloading and parsing research papers

I am trying to write a script which gets a research paper from a website by calling their API and then traverse it sentence-wise with some conditions. The paper is accessible in XML format. I am ...
1
vote
1answer
52 views

“Sequence full of colors” challenge on HackerRank

This is the challenge: You are given a sequence of N balls in 4 colors: red, green, yellow and blue. The sequence is full of colors if and only if all of the ...
2
votes
1answer
56 views

Guess Number Game - Console based game using Java

This game is pretty common for beginner projects. I wrote a version of this before all in Main - so here I challenge myself to recreate it in a more OO style. I wanted to take a more OO approach, so ...
1
vote
2answers
77 views

Advent of Code 2020, Day 10 in Ruby

I'm an amateur programmer making a career change into web development. I've found Advent of Code challenges are great way to sharpen my skills. I've cleaned up this solution for Day 10, 2020 as much ...
2
votes
3answers
103 views

DFS-based exhaustive word grid search

I have implemented an exhaustive depth-first grid search that searches for all possible words in the 8 connected regions. Is there any way I can make this faster or memory efficient than it is now? I ...
11
votes
2answers
407 views

Finding acronyms with >=1 letters at the start of each consecutive word

Problem I'm seeking a clean and efficient way to determine whether one string is an initialism/acronym of another. Example: IBM => International Business Machines However, a key condition for my ...
0
votes
0answers
45 views

A recursive_count Function with Unwrap Level for Various Type Arbitrary Nested Iterable Implementation in C++

This is a follow-up question for A recursive_count Function For Various Type Arbitrary Nested Iterable Implementation in C++, A recursive_count_if Function with Unwrap Level for Various Type Arbitrary ...
0
votes
1answer
34 views

Find a powerset of a set in C

The code below is an implementation of purely recursive solution to find a powerset of any given set. The input set is a string, and the output - array of strings. Both of them are wrapped into a ...
4
votes
2answers
63 views

Primality Test Refactoring

I devised a new primality test isPrimeNumber() below which determines if 1000000007 is prime. It works fine but the code looks unprofessional in my opinion. Is there any way to refactor it to make it ...
1
vote
0answers
57 views

A Function Applier for Applying Various Algorithms on Nested Container Things in C++

This is a follow-up question for A recursive_replace_if Template Function Implementation in C++, A recursive_copy_if Template Function Implementation in C++, A recursive_count_if Function with Unwrap ...
1
vote
0answers
45 views

A recursive_replace_copy_if Template Function Implementation in C++

This is a follow-up question for A recursive_copy_if Template Function Implementation in C++. Besides the recursive version std::ranges::copy_if, I am trying to ...
2
votes
1answer
48 views

A recursive_copy_if Template Function Implementation in C++

This is a follow-up question for A recursive_transform for std::vector with various return type and A recursive_transform Template Function Implementation with std::invocable concept in C++. Besides ...
1
vote
1answer
60 views

A recursive_transform Template Function Implementation with recursive_invoke_result_t and std::ranges::transform in C++

This is a follow-up question for A recursive_transform Template Function Implementation with std::invocable concept in C++, A recursive_transform Template Function Implementation with std::invocable ...
3
votes
2answers
100 views

Nested std::deque and std::vector Type Test Cases for recursive_transform Template Function in C++

This is a follow-up question for A recursive_transform Template Function Implementation with std::invocable concept in C++, A recursive_transform Template Function ...
2
votes
1answer
67 views

A recursive_transform Template Function Implementation with std::invocable Concept and Execution Policy in C++

This is a follow-up question for A recursive_transform Template Function Implementation with std::invocable concept in C++ and A recursive_transform Template ...
2
votes
1answer
100 views

A recursive_transform Template Function Implementation with std::invocable concept in C++

This is a follow-up question for A recursive_transform for std::vector with various return type, A recursive_transform Template Function with Execution Policy, A recursive_count_if Template Function ...
2
votes
1answer
59 views

A recursive_count_if Template Function with Execution Policy in C++

This is a follow-up question for Avoiding requires clause if possible on a series recursive function in C++ and A recursive_count_if Function with Automatic Type Deducing from Lambda for Various Type ...
1
vote
1answer
73 views

Avoiding requires clause if possible on a series recursive function in C++

This is a follow-up question for A recursive_transform_reduce Function for Various Type Arbitrary Nested Iterable Implementation in C++, A recursive_count Function For Various Type Arbitrary Nested ...
2
votes
1answer
77 views

A recursive_transform_reduce Function for Various Type Arbitrary Nested Iterable Implementation in C++

This is a follow-up question for A population_variance Function For Various Type Arbitrary Nested Iterable Implementation in C++. Thanks to G. Sliepen's answer, I am trying to implement the mentioned <...
1
vote
1answer
73 views

A population_variance Function For Various Type Arbitrary Nested Iterable Implementation in C++

This is a follow-up question for A Summation Function For Various Type Arbitrary Nested Iterable Implementation in C++, An arithmetic_mean Function For Various Type Arbitrary Nested Iterable ...
5
votes
1answer
132 views

A Various Container Type Arbitrary Nested Iterable Generator Function Implementation in C++

This is a follow-up question for std::array and std::vector Type Arbitrary Nested Iterable Generator Functions Implementation in C++ and std::deque and std::list Type Arbitrary Nested Iterable ...
6
votes
1answer
122 views

Non-nested std::deque and std::list Generator Function for arithmetic_mean Function Testing in C++

This is a follow-up question for A non-nested test_vectors_generator Function for arithmetic_mean Function Testing in C++ and An arithmetic_mean Function For Various Type Arbitrary Nested Iterable ...
2
votes
2answers
103 views

Pretty print directory structure in a JSON recursively

I am trying to pretty print the directory structure defined in a JSON. I do have a solution using recursion but I'm looking for feedback on how this solution can be ...
1
vote
0answers
46 views

A non-nested test_vectors_generator Function for arithmetic_mean Function Testing in C++

This is a follow-up question for An arithmetic_mean Function For Various Type Arbitrary Nested Iterable Implementation in C++. As Toby Speight's answer mentioned, some self-checking unit tests are ...
3
votes
1answer
83 views

An arithmetic_mean Function For Various Type Arbitrary Nested Iterable Implementation in C++

This is a follow-up question for A recursive_count Function For Various Type Arbitrary Nested Iterable Implementation in C++ and A Summation Function For Boost.MultiArray in C++. I am trying to ...
1
vote
3answers
99 views

Java recursive sort verification function for a linked list

It should return true, if there is no element that follow or the following elements are greater than their predecessors. ...
3
votes
0answers
129 views

LeetCode: Stone Game C#

https://leetcode.com/problems/stone-game/ Alex and Lee play a game with piles of stones. There are an even number of piles arranged in a row, and each pile has a positive integer number of stones ...
1
vote
0answers
35 views

std::deque and std::list Type Arbitrary Nested Iterable Generator Functions Implementation in C++

This is a follow-up question for std::array and std::vector Type Arbitrary Nested Iterable Generator Functions Implementation in C++ and the previous questions about recursive functions, including A ...
3
votes
1answer
148 views

std::array and std::vector Type Arbitrary Nested Iterable Generator Functions Implementation in C++

This is a follow-up question for the previous questions about recursive functions, including A Summation Function For Arbitrary Nested Vector Implementation In C++, A recursive_count_if Function For ...
2
votes
1answer
48 views

A recursive_count_if Function with Unwrap Level for Various Type Arbitrary Nested Iterable Implementation in C++

This is a follow-up question for A recursive_count_if Function For Various Type Arbitrary Nested Iterable Implementation in C++, A recursive_count_if Function with Specified value_type for Various ...
2
votes
1answer
67 views

A recursive_count_if Function with Automatic Type Deducing from Lambda for Various Type Arbitrary Nested Iterable Implementation in C++

This is a follow-up question for A recursive_count_if Function For Various Type Arbitrary Nested Iterable Implementation in C++ and A recursive_count_if Function with Specified value_type for Various ...
12
votes
2answers
556 views

Sudoku solver program written in modern c++

This is a simple program that solves a given Sudoku puzzle recursively. The input is provided as a file that contains the cells, 0 if empty, delimited by a , ...
1
vote
0answers
53 views

A recursive_count_if Function with Specified value_type for Various Type Arbitrary Nested Iterable Implementation in C++

This is a follow-up question for A recursive_count_if Function For Various Type Arbitrary Nested Iterable Implementation in C++. Thanks to Quuxplusone's answer and G. Sliepen's comments. Based on the ...
6
votes
3answers
934 views

Money change exam

I was asked to create a method that would: Return a Change object or null if there was no possible change The "machine" has unlimited bills of: 2, 5 and 10 The Change object must return the ...
2
votes
1answer
99 views

A recursive_count_if Function For Various Type Arbitrary Nested Iterable Implementation in C++

This is a follow-up question for A recursive_count Function For Various Type Arbitrary Nested Iterable Implementation in C++. Thanks to G. Sliepen's answer. Based on the mentioned suggestion, the ...
4
votes
1answer
74 views

A recursive_count Function For Various Type Arbitrary Nested Iterable Implementation in C++

This is a follow-up question for A Summation Function For Arbitrary Nested Vector Implementation In C++ and A Summation Function For Various Type Arbitrary Nested Iterable Implementation in C++. ...

1
2 3 4 5
21