recursion

Recursively searching a tree to get the binary coding for a character

Hi im trying to figure out how to recursively search a tree to find a character and the binary code to get to that character. basically the goal is to go find the code for the character and then write it to a file. the file writer part i can do no problem but the real problem is putting the binary code into a string. while im searching f...

how to iterate nested dictionaries in objective-c iphone sdk

Hi I have a json string converted unsing the JSON framework into a dictionary and I need to extract its content. How could I iterate to the nested dictionaries? I have already this code that allows me to see the dictionary: NSDictionary *results = [responseString JSONValue]; NSMutableArray *catArray = [NSMutableArray array]; for (id k...

Why does this work in DrRacket but not in Racket from the console

(define pick (lambda (num lat) (cond ((null? lat) (quote())) ((= (sub1 num) 0) (car lat)) (else (pick (sub1 num) (cdr lat)))))) (define brees (quote (a b c d e touchdown g h i))) (pick 6 brees) The language in DrRacket is set to Advanced Student. It also works fine in the IronScheme...

Maximum recursion depth?

I have this tail recursive function here: def fib(n, sum): if n < 1: return sum else: return fib(n-1, sum+n) c = 998 print(fib(c, 0)) It works up to n=997, then it just breaks and spits a "maximum recursion depth exceeded in comparison" RuntimeError. Is this just a stack overflow? Is there a way to get around ...

Recursion Recursion Recursion --- How can i Improve Performance? (Python Archive Recursive Extraction)

I am trying to develop a Recursive Extractor. The problem is , it is Recursing Too Much (Evertime it found an archive type) and taking a performance hit. So how can i improve below code? My Idea 1: Get the 'Dict' of direcories first , together with file types.Filetypes as Keys. Extract the file types. When an Archive is found Extract ...

PHP recursive function to retrieve all children of a category

Hello guys, I would like to write a recursive PHP function to retrive all the children for the specified category. I tried the one described here but it didn't output what I have expected. My categories table looks like this: CREATE TABLE `categories` ( `category_id` smallint(5) unsigned NOT NULL AUTO_INCREMENT, `category_name` var...

Recursive sql subset query, using connect by

I have two tables that look a little like this AGR_TERR_DEF_TERRS ID DEF_ID TERRITORY_ID (foreign key links to TERRITORIES.ID) TERRITORIES ID NAME PARENT_ID (parent_id and id are recursive) Given two DEF_IDs, I need a function which checks whether the territories of one is a complete subset of the other. I've been playing...

Thoughts on a recursive algorithm.

Hi. I have a problem at hand, which can be stated as follows. There are two set of nodes (in a bipartite directed graph), type1 and type2. For every node in the graph of type1, I have to find out a set which is constructed in this fashion: Let node1 be the first node of type1. Add node1 in the set. For node1, find out the list of nod...

PHP FTP Recursive download blocks with no apparent reason

Below are the functions that I use to download a FTP folder, recursively. I ran this several times, but after a successful run for like 1-2 mins, it always stops on the same spot, at the same file, generating this : ...... ...... Downloaded: login-bkg-bottom.gif Downloaded: login-bkg-tile.gif Downloaded: logo-ghost.png Downloaded: logo-...

How do I break out of recursive IEnumerable<T> loops using yield break?

I have the following method that works well, except the yield break statement only breaks out of the current enumerator. I understand why this is the case, but I am drawing a blank over how to propogate the yield break up through the recursive stack. private static IEnumerable<Node> FindChildrenById(IEnumerable nodes, string parentT...

How to convert a tree recursive function ( or algorithm ) to a loop one?

I have written a recursive Tree Function in pascal ( or delphi ) but i had an 'Out of Memory' message when I ran it. I need to turn the Calculate recursive function in this code to non-recursive function, can you tell me how please : program testing(input,output); type ptr = ^tr; tr = record age:byte; left,right:ptr; end...

Finding a prime number in Scheme using natural recursion

I'm still plugging away at the exercises in How to Design Programs on my own, but have managed to get stuck again. This time it's question 11.4.7: Develop the function is-not-divisible-by<=i. It consumes a natural number [>=1], i, and a natural number m, with i < m. If m is not divisible by any number between 1 (exclusive) ...

Mixin class to trace attribute requests - __attribute__ recursion

Hi, I'm trying to create a class which must be superclass of others, tracing their attribute requests. I thought of using "getattribute" which gets all attribute requests, but it generates recursion: class Mixin(object): def __getattribute__ (self, attr): print self, "getting", attr return self.__dict__[attr] I know why I ...

Trouble retrieving products under a complex category structure in PHP

Hello, I hope you guys can help me with this one. So, I have a products table and a categories table. The structure for the categories table is listed bellow. There will be about 20 categories with three or four levels deep. In order to get the category tree a wrote a recursive function and it is working fine. My new task is to displa...

jquery - recursively attach "submit" handlers to forms with ajax?

I'm using a modal plugin (colorbox) that has an option "onComplete". I can do the following to achieve part of the effect I'm going for (this is just the "onComplete" option): onComplete: function(){ $('.ajaxform').ajaxForm({ success: function(responseText){ $.colorbox({html:responseText}); } ...

[python] can a python class contain an instance of itself as a data container

Dear All, Can a python class contain an instance of itself as a data container may look like this? class A: def __init__(self, val): self.a = A(val) self.val = val aa = A(2) #this will cause RuntimeError: maximum recursion depth exceeded my purpose is using this class as a data container contain a copy inside if...

How to create a lazy-seq generating, anonymous recursive function in Clojure?

Edit: I discovered a partial answer to my own question in the process of writing this, but I think it can easily be improved upon so I will post it anyway. Maybe there's a better solution out there? I am looking for an easy way to define recursive functions in a let form without resorting to letfn. This is probably an unreasonable reque...

How to script scp -r copy ?

Hello, I can't seem to be able to convince scp to behave. For test data ubuntu@domU-12-31-38-00-D4-F1:/tmp$ find /tmp/a1/ /tmp/a1/ /tmp/a1/a2 /tmp/a1/a2/a3 On issuing the command ubuntu@domU-12-31-38-00-D4-F1:/tmp$ scp -r /tmp/a1 domU-12-31-38-00-E2-52.compute-1.internal:/tmp/a1 I would expect the same directory structure created...

Parsing the Freebase Topic HTTP API - JSON & Javascript

Hi, I am trying to parse a JSON output: http://www.freebase.com/experimental/topic/standard?id=/en/colonel_sanders I'd like to put the basic data into an array using Javascript. In the "properties" object I'd like to grab any "text" element one level under "properties" as a label and grab the "text" under the "values" object to match t...

Common recursion pattern

I'm getting used to Haskell's higher-order functions. Usually I can replace explicit patterns of recursion with functions like map, fold, and scan. However, I often run into the following recursion pattern which I don't understand how to express using higher-order functions: f (x:[]) = k x f (x:xs) = g x (f xs) For instance, sup...