recursion

MySQL set storing

I have a couple of tables in a web application I'm coding in PHP, and I would like to know if this would be good pratice. CREATE TABLE `products`( `product_id` int NOT NULL auto_increment, `name` varchar(255) NOT NULL, `variations` varchar(255) default NULL, PRIMARY KEY (`product_id`) ) CREATE TABLE `variations`( `variation_...

Expressing recursion in LINQ

I am writing a LINQ provider to a hierarchal data source. I find it easiest to design my API by writing examples showing how I want to use it, and then coding to support those use cases. One thing I am having trouble with is an easy/reusable/elegant way to express "deep query" or recursion in a LINQ statement. In other words, what is th...

How can I recursively use the Global in VIM?

Is something wrong in ":g-2-g/3/" or is the recursion in the global just missing? I can not understand a reason for the error: E147: Cannot do :global recursive How can I get a recursive global search in VIM? [Neil's initial Suggestion with the operator \| ] g/1.*2\|2.*1/ A disadvantage is that the combinations expand with n nu...

How can I detect recursing package calls in Perl?

I have a Perl project were I just had a problem by making a circular package call. The code below demonstrates the problem. When this is executed, each package will call the other until all of the memory of the computer is consumed and it locks up. I agree that this is a bad design and that circular calls like this should not be mad...

MSBuild Recursive Copy with %(ConfigurationToBuild.PlatformToBuild)

Hi I have the following task, which because of the combination of DestinationFiles and DestionationFolder does not work, but it grabs the concept of what I want to do: <CreateItem Include="$(Destination)\**\*.Generated.*.*"> <Output TaskParameter="Include" ItemName="GeneratedFiles" /> </CreateItem> <Copy Condition=" '%(Configuration...

Recursively List all directories and files

Hi I would like to recieve the following output - Suppose the directory structure on the file system is like this: -dir1 -dir2 -file1 -file2 -dir3 -file3 -file4 -dir4 -file5 -dir5 -dir6 -dir7 The output from the script must be like: Directories: /dir1 /dir1...

What's a good recursion question to ask a prospective employee?

I like to touch on recursion during interviews and am looking for some new ideas. My desired format is to ask the candidate to implement something without any restrictions. Then if he doesn't do it recursively, ask him if it can be done. Currently, I have Fibonacci and factorial which are a bit too standard for my liking. Recent graduat...

How should I create the subsonic 3.0 DB context class?

I'm new to SubSonic (of all flavours), but thought I might as well start with 3.0, because I'd like to use Linq, and I get the impression 3.0 is not that far away from release. I tried the alpha download .zip, but that seems pretty old and didn't singularize table class names, so I'm now running from the latest trunk SVN version (rev62)...

Why does this code cause a stack overflow?

The following would cause stack overflow for large 'n', and I can understand why. def factorial(n) (n > 1) ? (return (n * factorial(n - 1))) : (return 1) end Why does the following cause overflow as well? def factorial(n, k) (n > 1) ? (return factorial(n - 1, lambda {|v| return k.call(v * n)})) : (return k.call(1)) end ...

Optimizing a non-tail-recursive function.

I have this function whose essential operations are outlined as follows: function render($index) { foreach($things[$index] as $key => $data) { echo '<div>'; /* irrelevant operations */ if(isset($data['id'])) { echo '<div class="wrap">'; render($things[$data['id']]); echo '<...

How to improve this piece of code?

My solution to exercise 1.11 of SICP is: (define (f n) (if (< n 3) n (+ (f (- n 1)) (* 2 (f (- n 2))) (* 3 (f (- n 3)))) )) As expected, a evaluation such as (f 100) takes a long time. I was wondering if there was a way to improve this code (without foregoing the recursion), and/or take advantage of multi-core box. I am usi...

StackOverflowException without recursion or infinite loop?

Hello, Background I have a DataGridView control which I am using, and I added my handler below to the DataGridView.CellFormatting event so the values in some cells can be made more human-readable. This event handler has been working great, formatting all values without issue. Recently however, I have discovered a very rare circumstan...

How far does recursion execute into your function in C++?

I've written recursive functions with the guidance of a friend who is teaching me C++ (as a first language). However, I don't really understand what is going on. He helped me (and the SO community, as well) write a merge sort function. std::vector<int> mergeSort(std::vector<int> original) //code here to create two vectors, farray and s...

Using recursion to sum numbers

I have just been studying the concept of recursion and I thought that I would try a simple example. In the following code, I am attempting to take the numbers: 1, 2, 3, 4, 5, and add them together using recursion. I expected the result to be 15, but my code is returning 16. What am I doing wrong? Code: static void Main(string[] a...

Using arrays with recursion

Now that I am using recursion to calcuate the sum of numbers, I want to do something slightly different. The following is my code that will sum the numbers 1,2,3,4,5. How would I modify my code to place the numbers 1, 2, 3, 4, 5 into an array and then use it in the recursion method? I have tried so many different attempts and I am app...

Is recursion generally considered to be an outdated method of traversing compared to using a stack?

I've been reading in a couple of places where people are opting to use a Stack instead of recursion. Is this because recursion is seen as being an outdated way to get-the-job-done or are both methods equally applicable in different contexts? ...

Populate WinFrom TreeView from DataTable

I have a WinForm TreeView Control that displays the Parent Child relationship of CaseNotes(I know that means nothing to most of you but it helps me visualize the answers). I have a DataTable of the CaseNotes that I need to display. The Parent/Child is defined as: If the row has a ParentNoteID then it is a childNode of that note other...

How do I know if a function is tail recursive in F#

I wrote the follwing function: let str2lst str = let rec f s acc = match s with | "" -> acc | _ -> f (s.Substring 1) (s.[0]::acc) f str [] How can I know if the F# compiler turned it into a loop? Is there a way to find out without using Reflector (I have no experience with Reflector and I Don't know C#)?...

Nested classes and recursion

Say i have these two classes public class Container { public string name { get; set; } public Inner Inner { get; set; } } public class Inner { public string text { get; set; } public Inner2 Innert2 { get; set; } } public class Inner2 {} How would i go, given an instance of ...

How to recursively chmod on subdirectories?

I want to recursively chmod all of the subdirectories below my calcium directory: chmod a+wx calcium How do I change the above command to do this? I believe I'm using bash shell although I'm not sure how to verify this. ...