recursion

How do I store the results of this recursive function?

I have the following PHP code which works out the possible combinations from a set of arrays: function showCombinations($string, $traits, $i){ if($i >= count($traits)){ echo trim($string) . '<br>'; }else{ foreach($traits[$i] as $trait){ showCombinations("$string$trait", $traits, $i + 1); }...

Is it possible to programatically recurse up a stack trace to a particular calling assembly?

Hi folks, i'm wondering if it is possible to programattically recurse up a stack trace to a particular assembly. I'm using StructureMap and it creates an instance of a particular class, to inject into another class. kewl. When i'm in the constructor of the injected class, i wish to see what was the parent class and the stack trace more...

Code for Variations with repetition (combinatorics)?

Does anyone have Java code for generating all VARIATIONS WITH REPETITION? There are plenty of permutation and combination examples available, and variations must be the easiest one... It feels stupid to waste time to reinvent the wheel (it must be plenty of code written for this). An example of VARIATIONS WITH REPETITION could be like...

One-liner to Recursively List Directories in Ruby?

What is the fastest, most optimized, one-liner way to get an array of the directories (excluding files) in ruby? How about including files? ...

PHP recursive function to retrieve hierarchical data from flat table (Zend Framework)

I'm trying to retrieve hierarchical data from a table but am failing to do so. The table has (for now) the following columns: ifc_key, ifc_name, ifc_parent. ifc_key is not used. (primary key, but not used for this function. The purpose is to get an array. Each element is a "parent" interface. (so all these root elements are ifc_name v...

Recursively finding the lowest level item in C#

What am I missing in GetLowestLevelFoo? Why do I get the answer A instead of D? public class Foo { public string Name { get; set; } public Foo ChildFoo { get; set; } } [TestFixture] public class Recursion { [Test] public void Test() { Foo foo = new Foo ...

Recursive Splay Tree

I am trying to implement a recursive splay tree, bottom up. I recurse down to the node I am need to splay up, and I find the parent and grandparent of that node. Then I am able to either zig zag or zig zig depending on the situation just fine. The problem is after this is done, I return the node which has been splayed once to the previou...

Recurse through properties of a class

Take this sample class as an example: [AttributeUsage(AttributeTargets.All, AllowMultiple=true)] public class BugFixAttribute : System.Attribute { public int BugId { get; private set; } public string Programmer { get; private set; } public DateTime Date { get; private set; } public string Comments { get; set; } ...

MySQL - Recursing a tree structure

I have a database table which link locations together; a location can be in a location, which can be inside another location. location (<id>, ....) location_parent (<location_id>, <parent_id>) Here's the MySQL/PHP to go down for a depth of one: $sql = "SELECT id FROM se_locations_services WHERE parent_locationid IN ( SELECT location_...

jQuery plugin "lazy" fails to load two jQuery plugins with $.getJSON calls in each of them: too much recursion ONLY in Firefox

Plugin: jQuery lazy() I ask here because the project page itself seems to be dead. What steps will reproduce the problem? 1. embed two jQuery-Plugins that are both using the $.getJSON function results in a "too much recursion error" in firefox. If the same scripts are referenced with lazy it works fine. Problem only persits in firefox...

PHP SimpleXML recursive function to list children and attibutes

I need some help on the SimpleXML calls for a recursive function that lists the elements name and attributes. Making a XML config file system but each script will have it's own config file as well as a new naming convention. So what I need is an easy way to map out all the elements that have attributes, so like in example 1 I need a simp...

Common table expressions, how to avoid infinite recusion when traversing a graph?

I have a simple weighted graph A 1 / \\ 0.5 / \\0.5 B C Suppose this describes a family and A is the father, B is the son and C is the mother. Let's say B is studying in an university and A has bought an apartment for him. A is living with C in a house which is commonly owned, 50-50. I want to transform the graph into a...

(Java) Find all possible pairs in an array

Its when I try to do stuff like this I realise I really need to go to university! Anyway I have an array of strings (275) I need to loop through them and create strings of all the possible pairs, in java. I've been learning about recursion but I cant find the answer for this. Thanks ...

Implementing Recursion from psuedo-code (NTRUEncrypt)

Hello again everyone. I am required to implement the NTRU Public Key Cyptosystem as part of my final year University project. I'm trying to implement an algorithm that multiplies long polynomials via recursion, however I'm quite bogged down in trying to understand the pseudo-code. Algorithm PolyMult(c, b, a, n, N) Require: N, n, and the...

Recursion causes exit to exit all JFrames (terminates app)

I have made an application that gives the user the option to open up a new spawn of the application entirely. When the user does so and closes the application the entire application terminates; not just the window. How should I go about recursively spawning an application and then when the user exits the JFrame spawn; killing just that ...

PHP recursive directory path

i have this function to return the full directory tree: function getDirectory( $path = '.', $level = 0 ){ $ignore = array( 'cgi-bin', '.', '..' ); // Directories to ignore when listing output. Many hosts // will deny PHP access to the cgi-bin. $dh = @opendir( $path ); // Open the directory to the handle $dh while( false !== ( $file =...

recursive function to get all the child categories

Here is what I'm trying to do: - i need a function that when passed as an argument an ID (for a category of things) will provide all the subcategories and the sub-sub categories and sub-sub-sub..etc. - i was thinking to use a recursive function since i don't know the number of subcategories their sub-subcategories and so on so here is w...

Recursive calls in Pentaho Data Integration

Is it possible for a step or transformation in Pentaho Data Integration to call itself, passing the results of the previous call as parameters/variables? My first thought was to create a loop in a transformation, but they don't seem to be allowed... ...

Python recursive function error: "maximum recursion depth exceeded"

I solved Problem 10 of Project Euler with the following code, which works through brute force: def isPrime(n): for x in range(2, int(n**0.5)+1): if n % x == 0: return False return True def primeList(n): primes = [] for i in range(2,n): if isPrime(i): primes.append(i) retu...

How to handle recursive parent/child problems like this?

In web dev I come across these problems a lot. For example, we have a giant list of URLs that are in this format: /businesses /businesses/food /businesses/food/wendys /businesses/food/wendys/chili /businesses/food/wendys/fries /businesses/food/wendys/chicken-nuggets /businesses/pharmacy/cvs /businesses/pharmacy/cvs/tooth...