recursion

How to create a function in ML using a Recursive Datatype

Given the datatypes: datatype bunch = One of int | Group of bunch list; datatype 'ex bunch = NIL | One of 'ex | Group of 'ex * 'ex bunch; How can I design a function to, for example, return the sum of this recursive function. I understand how to define a recursive function and slig...

Recursively replace keys in an array

Hi, I can't quite work this out... I was hoping that there would be a default PHP function to do this, but it seems there isn't. The code I've found online seems to not really work for my situation, since often people have only need to the modify array values and not their keys. I basically need a recursive function that replaces every...

powershell error checking during file copy with recursion

I have a program that copies folders and files recursively. example: Copy-Item -path "$folderA" -destination "$folderB" -recurse Sometimes the files do not copy. Is there a way to "step inside the recursion" or a better way to do it, so I can enable some kind of error checking during the process rather than after wards. Possibly even...

Recursion runtime implementation Java vs. other/functionals languages?

I like recursion, but at Java you meet an dead end at some point. E.g. I had a case where recursion with ~100K iterations wouldn't work (StackOverflowError). Badly I had to switch to annoying "imperative looping" for this runtime stack-limit reasons. I wonder how other (especially functional) languages bypass stack-overflowing during r...

Handling tree in a MySQL procedure

The idea is simple - I have two tables, categories and products. Categories: id | parent_id | name | count 1 NULL Literature 6020 2 1 Interesting books 1000 3 1 Horrible books 5000 4 1 Books to burn 20 5 NULL Motorized vehicles 1000 6 ...

Prevent Recursive jQuery AJAX incrementing browser memory usage

I'm using recursive jQuery AJAX to callback values from the server every second. However, this seems to be incrementing the amount of memory usage my browser has. I'm using FireFox and I have FireBug installed which I believe to be the culprit as this logs every callback in its Console. My first question is, am I right in saying this i...

Understanding recursion

I am struggling to understand this recursion used in the dynamic programming example. Can anyone explain the working of this. The objective is to find the least number of coins for a value. //f(n) = 1 + min f(n-d) for all denomimations d Pseudocode: int memo[128]; //initialized to -1 int min_coin(int n) { if(n < 0) return INF; ...

recursively loop over javascript object?

Hi there. I am trying to create a function which, When given an object will output something like <div> reason : ok status : 0 AiStatistics : null CurrentSeasonArenaStatistics : null <div> Player <div> CampaignProgressCoop : CompletedLegendary CampaignProgressSp : PartialHeroic <div> ReachEmblem <div> ba...

Unknown recursions of a XML structure with SAX

I have to parse a XML structure in JAVA using the SAX parser. The problem is that the structure is recursive with an unspecified count of recursions. This still is not such a big deal the big deal is that I can't take advantage of the XML namespace functionality and the tags are the same on every recursion level. Here is an example of t...

Need to generate every unique combination of an array of files recursively

I've researched and found LOTS of similar requests, but nothing was quite what I needed. Here is my problem. I'm working in C#, and I have a FileInfo[] array with an unknown number of elements in it. FileInfo[] files = new FileInfo[] { new FileInfo(@"C:\a.jpg"), new FileInfo(@"C:\b.jpg"), new FileInfo(@"C:\c.jpg"), new...

C#: Code to fit LOTS of files onto a DVD as efficiently as possible

I need to write an application that will take a list of files (some large, some small) and fit them onto DVDs (or CDs, or whatever) as efficiently as possible. The whole point of this application is to use up as much of the 1st disc before moving onto the 2nd disc, filling the 2nd disc up as much as possible before moving onto the 3rd d...

Removing Left Recursion in a Context Free Grammar

Trying to figure out removing left recursion in context free grammars. I'm used to certain forms, but this one has me a bit boggled. S --> S {S} S | (A) | a A --> {S} A | epsilon I also have to design a decent parser, which I can do. However, figuring out this left recursion (especially on the first one) has me confused. ...

Algorithm for Postage Stamp Problem

The postage stamp problem is a mathematical riddle that asks what is the smallest postage value which cannot be placed on an envelope, if the letter can hold only a limited number of stamps, and these may only have certain specified face values. For example, suppose the envelope can hold only three stamps, and the available stamp values...

How do I use a recursive array iterator to process a multidimensional array?

I'm trying to get something like this working: function posts_formatter (&$posts){ foreach ($posts as $k => $v){ if (is_array($v)){ posts_formatter($v); }else{ switch (strtolower($k)){ # make email addresses lowercase case (strpos($k, 'email') !== FALSE): ...

Haskell tail-recursion performance question for Levenshtein distances

I'm playing around with calculating Levenshtein distances in Haskell, and am a little frustrated with the following performance problem. If you implement it most 'normal' way for Haskell, like below (dist), everything works just fine: dist :: (Ord a) => [a] -> [a] -> Int dist s1 s2 = ldist s1 s2 (L.length s1, L.length s2) ldist :: (Or...

How to 'merge' some array elements into a element of the same array?

Hi all, i have 2 arrays: $foo = array( '1' => '2', '3' => array( '4' => '5' ), '6' => array( '7' => '8', '9' => '10', '11' => array( '12' => '13', '14' => '15' ) ) ); $bar = array( '1', '6' => array( '7', '11' => array( ...

Fatal error: Nesting level too deep - recursive dependency?

I have a complex hierarchy of nested objects, with all of the child objects (stored an array of objects in the parent class) containing a property linking back to their parent: fairly simple and straightforward, with no real problems. If I do a var_dump of any object in the hierarchy, I'll get a recursive reference in the dump, exactly a...

Linked List Losing nodes after leaving recursive function

struct Letter { char let; Letter *next; }; Please look at the function below called addLETTERS(). int main() { Letter *Top = 0; Letter *head = 0; char letters = 'a'; head = new Letter; Top = new Letter; MakeNull(head); MakeNull(Top); addLETTERS(Top, head,letters); retur...

Concatenate sequence from a predefined datastructure

Hello, I've been struggling a little to build this piece of code, and I was wondering if there are others more simple/efficient way of doing this: fsSchema = {'published': {'renders': {'SIM': ('fold1', 'fold2'), 'REN': ('fold1', 'fold2')}}} def __buildPathFromSchema(self, schema, root=''): metaDirs = [] for dir_ in sc...

Recursive function not returning a value in PHP

I've got a recursive function defined as follows private function _buildPathwayRecurse(&$category, &$reversePathway = array()) { $category->uri = FlexicontentHelperRoute::getCategoryRoute($category->id); $reversePathway[] = $category; if ($category->parent_id != 0) { $category = $this->_getCatForPathway($category->parent_id);...