47,439 questions
4
votes
2
answers
112
views
Algorithm to recursively search a dictionary or list and return the path of each found element
I keep almost solving this.
I've got a data set of python dictionaries that contain both lists and dictionaries that also contain lists and dictionaries.
I want to find all instances of a substring in ...
-3
votes
0
answers
85
views
Why won't this recursive function return true [closed]
public static boolean isWordSymmetric(String[] words, int start, int end){
if (words[start].toLowerCase().equals(words[end - start].toLowerCase())) {
if (start == end){
...
0
votes
0
answers
52
views
How to transform recursion into iteration [closed]
I'm making a parser combinator library that gets compiled into imperative code.
I've figured out how to compile tail recursion, simple recursion, and cross referential recursion, but can't figure out ...
3
votes
2
answers
155
views
Recursive C function for creating number permutations
I do understand I have mistakes in this code
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int diziyi_yazdır(int dizi[], int dizi_uzunluğu)
{
for (int i ...
-2
votes
1
answer
174
views
Why does my Quick Sort implementation sometimes cause stack overflow on large arrays with duplicates? [closed]
I’m trying to implement an in-place Quick Sort in Python. I have two slightly different versions of my partitioning logic, and I’m confused because both seem correct on small arrays, but the second ...
2
votes
1
answer
114
views
How to write an accumulative recursive function in J without looping
At the risk of asking a question with an obvious solution: if I have a function in J that takes two arguments and returns two arguments and I want to accumulate the answer's second argument and to use ...
3
votes
3
answers
85
views
How does the recursion in generateParenthesis go from backtrack(3, 3) to backtrack(2, 1)?
I am working on LeetCode problem 22. Generate Parentheses using a recursive backtracking approach in Python. The function works, but I’m having trouble understanding the flow of recursion, ...
1
vote
2
answers
149
views
How exactly does recursion work in x86 assembly?
My question is focused specifically on assembly (intel). In C for example, recursion can be done with a simple return command but in assembly I feel like there's a lot more things going on, especially ...
0
votes
1
answer
86
views
How to disable radio button on all levels in a recursive Angular form component based on a specific level's value
this is kind of a continuation of an improved version of an old question of mine
so basically I have a recursive Angular form and I’m using to manage a folder hierarchy. Each folder has a radio button ...
1
vote
2
answers
146
views
Given the string input, how can we traverse the binary tree recursively
Let's say our binary tree (bt) looks like this:
Node* root = new Node();
root->left = new Node("B");
root->right = new Node();
root->right->right = new Node("A");...
-1
votes
2
answers
164
views
Why does python limit recursion depth, and how is this limit decided?
# Iterative factorial function to safely compute very large factorials without hitting Python's recursion limit.
# Recursive functions have a maximum depth, usually 1000, and factorial(2000) would ...
2
votes
1
answer
104
views
Sequential compilation times of a jax-jitted recursive function
I have a recursively defined function my_func that is jitted using jax.jit from the jax library. It is defined below:
# Imports
import jax
import jax.numpy as jnp
from functools import partial
import ...
0
votes
1
answer
67
views
JQ will not deep copy arrays with recursive algorithm
When using this algorithm:
jq -s 'def deepmerge(a;b):
reduce b[] as $item (a;
reduce ($item | keys_unsorted[]) as $key (.;
$item[$key] as $val | ($val | ...
0
votes
1
answer
34
views
Display tree depth using VLT recursion
I'm trying to render a tree structure using VLT, by indenting the rendering depending on the level it's on.
I tried to use a recursive macro which passes on the $indentLevel variable (see code below). ...
1
vote
2
answers
91
views
XML with attributes to array in PHP
I am trying to convert an XML string into multi-dimensioned PHP array. The difficulties are that XML comes with attributes and has nested values. My code works at parent level data but I am not sure ...
0
votes
0
answers
157
views
Stop Condition for Self-Referential Marcos
Background
I am on an ARM Cortex-A72. To access bit fields of my core's system registers I use a macro code generation mechanism. For the sake of simplicity, I replaced void operator=(const uint64_t v)...
5
votes
2
answers
198
views
Improve implementation of a "widget tree structure" in Qt6 [closed]
Let me introduce first the problem. I will present a simplification of my QT6 project app (in C++) to not make it too difficult to read, as the original code has lots of unnecesary things for this ...
14
votes
1
answer
360
views
Why does Deducing-This lambda require `this` to be a reference or capturing variables by reference?
Why does this code output garbage on GCC like there is a UB?
auto data = std::vector{1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
auto output = [data](this auto self, size_t i) {
if (i >= 10) {
...
1
vote
1
answer
99
views
Why am I getting this RecursionError?
I'm working on making a program to read a chart of accounts and turn it into a tree of Account objects, which I will be doing stuff with later. The chart of accounts in question has several levels of ...
0
votes
1
answer
104
views
Recursive function to create and populate dynamic-depth nested dictionary [closed]
I am attempting to build and populate a data structure consisting of multiple, but variable count, nested dictionaries in C#. I am currently using a recursive function to do so.
The data stored in the ...
0
votes
0
answers
32
views
recursive sum of totals by org and descendants in redshift
I have a table like this:
total
alert
group_id
hlevel
full_path
parent_id
root_group_id
5100FFFF-60B6-D5CD-FCCD-A8A3E03F0000
1
BizA\DivA
5100FFFF-60B6-D5CD-BFBA-A8A3E03F0000
5100FFFF-60B6-D5CD-FCCD-...
0
votes
1
answer
122
views
Python lambda returns 0 [closed]
Is there a simple way to return 0 with a lambda function using and and or operators?
For example, consider this function to sum elements in an array:
sum = lambda tab: tab == [] and 0 or tab[0] + sum(...
2
votes
1
answer
114
views
I can't understand recursive part of FFT in Python
So basically I have this code of FFT implemented in Python for 2^m samples.
def fft(x):
N = len(x)
if N == 1:
return x
even = fft(x[0::2])
odd = fft(x[1::2])
result = [0] *...
4
votes
2
answers
76
views
Graph recursive walk in Scheme
I have an undirected graph which nodes are numbered from 0 to 5. Adjacencies are given with a vector of lists #((1 2) (0 3) (0) (1) (5) (4))), thus node 0 is connected to nodes 1 and 2, node 1 is ...
1
vote
2
answers
88
views
Is there a way to ignore specific subfolders when using DirectoryInfo.EnumerateFiles without manual recursion?
I'm using the following code to get all files of given extensions inside a folder with it's respective subfolders.
string path = "C:\\FolderA\\FolderB\\FolderC\\FolderD";
List<string> ...
3
votes
1
answer
104
views
How do I make a Prolog rule that only reads the lists inside lists?
I am somewhat new to Prolog, having only practised for a few months so far. I am stumped on the following problem and nothing I googled seemed to help.
I wrote the following code into a Prolog ...
0
votes
2
answers
91
views
Efficiently Count Number of Ones at Deepest Level in Recursive Floor-Ceil Splitting of Large Binary Number
I have a number represented as a large binary string (length can be up to 1 million bits). The number is recursively split as follows:
At each step, divide the number
x into two parts:
floor(x/2) and ...
0
votes
0
answers
150
views
How to implement a generalized N-Sum algorithm for variable k (user input) in Java? [duplicate]
I’ve already solved 2-Sum and 3-Sum problems:
2 sum uses a HashMap to check if target - nums[i] exists in HashMap.
3 Sum sorts array and then uses 2 pointers.
Yesterday, during Flipkart GRID Coding ...
2
votes
1
answer
265
views
How to implement a recursive distance function for Hex game AI evaluation?
I'm working on a Hex game AI that uses the alpha-beta pruning algorithm, and as part of evaluating the board state.
More detailed information about this distance metric can be found in this paper (see ...
0
votes
0
answers
66
views
Control recursive function evaluation depth in eval
As an exercise, to get a good idea of what Z3 can and can't do, I was trying to solve a "coraline" puzzle. This is a rectangular grid, where each square is a graph node of degree two: each ...
-1
votes
1
answer
84
views
Why does modifying the returned pair from a recursive call break my solution in Binary Tree Consecutive Sequence II?
I'm trying to solve the Binary Tree Longest Consecutive Sequence II problem (Leetcode 549). The goal is to find the length of the longest consecutive path (increasing or decreasing) in a binary tree. ...
4
votes
2
answers
184
views
C with inline assembly - recursive function that calls within the asm statement
I am fairly new to assembly.
After compiling, when I run the code below, I get a segmentation fault.
I am trying inline assembly with recursion. I am compiling this code with cxxdroid.
int ...
2
votes
1
answer
75
views
Where did I mess up using the stack in 68k Assembly (recursive factorial)
I'm trying to implement a recursive factorial function in M68K assembly using the stack to pass parameters. The code almost works: the recursion and multiplication behave as expected, and D0 contains ...
0
votes
0
answers
54
views
Retrieve all pages iteratively using completablefuture
DAO has methods that return completableFuture. To avoid fetching huge result at once, I want to fetch it in pages from DB.
The recursive solution stops when result size < pageSize
However, to avoid ...
1
vote
2
answers
104
views
Implementing a factorial function in Scala
I'm working out of Scala for the Impatient (3rd Edition). (I'm not doing this for a class.). I'm trying to implement a factorial function using to and reduceLeft without a loop or recursion. This ...
0
votes
1
answer
43
views
Antlr4 simple direct right recursive not work
exp: 'a' exp | 'a';
If the input is just an 'a', I get a error. Doesn't antlr4 support direct right recursive?
I have noticed that antlr4 supports direct left and right recursive. Why this simple ...
1
vote
1
answer
41
views
Lightroom plugin to create published collection set
I'm beginning with programming with Lua and want to create a plugin that loops through a folder structure and creates Published collection sets (and smart collection sets afterward).
I've come this ...
0
votes
1
answer
43
views
allocatable recursive one directional list, sort by selection. fortran
its a task for my uni, and i thought i would be able to make it, but its the 5th day in a raw.
i have to make in recursive, and i have to make it sort by selection, so
I am sorting surnames by ...
1
vote
1
answer
141
views
How to use a recursive CTE in a JOIN statement
I'm working on converting an old database and queries to recursive CTEs. In the current code, I'm storing hierarchical data as a dash separated list of 0 padded strings. So as an example, I may have ...
4
votes
1
answer
147
views
Why does a recursive lambda with deduced return type not work?
int main() {
auto fn = []<typename T>(this auto&& self, T n) {
if (n > 0) {
self(n - 1);
}
};
fn(3);
}
Compiled with clang-20 -std=c++23 but ...
-3
votes
2
answers
244
views
Why does my recursive pow(x, n) implementation cause a stack overflow for large n? [duplicate]
I'm trying to implement a recursive power function in C++, but it fails with large n due to stack overflow. Here's the code:
class Solution {
public:
double myPow(double x, int n) {
long ...
-1
votes
1
answer
73
views
What form of recursion is occurring in the "insert "and "list_all" methods of this code?
I am struggling to understand the recursion going on in the insert, _insert_recursive and _inroder_traversal methods. For context, I know recursion and the concept is not strange to me, I struggle to ...
2
votes
3
answers
147
views
Cut operator not discarding choice points?
Disclaimer: Yes, this is for an assignment, but I think I have an alternative solution already. I just want to figure out why this initial attempt did not work because I can't understand why it isn't ...
0
votes
1
answer
48
views
finding of parent of an html node in javascript using recursion? [duplicate]
Basically I need a less stupid way to do this:
var x = getElementById('not-important');
x.parentElement.parentElement.parentElement.parentElement....parentElement.style.display = 'none';
In my case ...
1
vote
3
answers
117
views
Recursively convert multidimensional array data into new multidimensional variables with hierarchical metadata included
I have an array of some parameters (like a YAML config file) and this need to be written to database finaly with primary ids and so on.
For example this is a part of my array:
$settings = [
'basic'...
0
votes
1
answer
44
views
Jekyll recursive include causing "Nesting too deep" error when rendering nested comments
I'm working on a Jekyll site and encountering a "Nesting too deep" error when trying to render nested comments using a recursive include. Here's a simplified version of my template:
{% ...
0
votes
1
answer
80
views
understanding a part of recursion for a binary search tree
Hello I basically need to implement a recursive function for insertion of a binary tree. I already implemented the chunk of insertion function (wether it's largest or smaller than root) but there's an ...
-1
votes
3
answers
159
views
How to decode nested numeric patterns in strings like 2[2[32]1[82]] in JavaScript?
I'm trying to solve a variation of the LeetCode "Decode String" problem in JavaScript. The adapted challenge could be formulated as:
Given an encoded string, return its decoded string.
The ...
1
vote
1
answer
75
views
Runtime Error in Recursion in Subsequences
I am writing a recursive function to create all possible subsequences of a string and return the set of strings as a vector. This is a challenge from Coding Ninjas. I recurse over each char in the ...
-3
votes
1
answer
107
views
How to convert call of a python object's nested attributes to string while returning a value?
I have trouble resolving a recursion issue, how can I build a class which would behave like this:
print the requested attributes from it: o.foo.bar would print "o.foo.bar" when called.
same ...