recursion

Recursive Bulk Edit in Linux

I am trying to change certain lines in multiple files (scattered in subfolders) without having to edit each file one by one. I was given by Chas. the following perl -pi.bak -e 's{[^/]Css/Template.css}{/Css/Template.css}' * and it worked like a charm but was wondering if this command or similar can be done recursively in one shot ...

Getting friends within a specified degree of separation

Hi, all. I'm a very, very new programmer. My language of choice at the moment is Python, and I feel like I have a decent feel for it. I'm just now starting to learn about recursion. (By the way, if anyone could recommend a good guide on this, please let me know!) Just so you all know, this question is very elementary, and the code I'm...

Can every recursion be converted into iteration?

A reddit thread brought up an apparently interesting question: Tail recursive functions can trivially be converted into iterative functions. Other ones, can be transformed by using an explicit stack. Can every recursion be transformed into iteration? The (counter?)example in the post is the pair: (define (num-ways x y) (case ((= x 0...

Month wise totals in columns

Hello, I've a table (Consumption) as follows: DocDate ItemCode Quantity 01.01.09 A 5 02.01.09 A 6 and so on.. for the whole year I need results as follow: ItemCode Jan09Total Feb09Total Mar09Total The problem is that the quantities should be summed up for the months, which should be in columns and acco...

Writing Recursive StoredProcedures

Basically what i want in my stored procedure is to return a list of tables, store this list in a variable; i need to go through every item in my list to recursively call this storedprocedure. In the end i need an overall listOfTables built up of this recursion. Any help would be most appreciated ...

Python recursion and return statements

Hi, I'm fairly new to Python and recursive functions as a whole, so pardon my ignorance. I am trying to implement a binary search tree in Python and have the following insert method (taken out of a class): def insert(self, key, root=None): '''Inserts a node in the tree''' if root == None: root = self.root if root.k...

What is implicit recursion?

What is implicit recursion? How is it different from explicit recursion? ...

MatLab recursion error (beginner)

Ok. So i've got two function in MatLab that are calling each other. Riemann.m function I = Riemann(f, dx, a, b) x = a:dx:b; fx = f(x).*dx; I = sum(fx); and myfunc.m function f = myfunc(x) f = sin(1./x); for n=1:100 I = Riemann(@myfunc, 0.001, 1/n, 1); end plot(I) The problem is getting that to run. How...

Recursion algorithms: suggested patterns and practices?

I am writing a utility that reflects on two object graphs and returns a value to indicate whether the graphs are identical or not. It got me thinking, is there a generally accepted pattern for writing a recursion algorithm that returns a value from some where in the recursion? My solution would probably use a ref parameter and look som...

Recursion in an ASP.NET MVC view

I have a nested data object for a set of items within categories. Each category can contain sub categories and there is no set limit to the depth of sub categories. (A file system would have a similar structure.) It looks something like this: class category { public int id; public string name; public IQueryable<category> cat...

Recursive Function palindrome in Python

I need help writing a recursive function which detects whether a string is a palindrome. But i can't use any loops it must be recursive. Can anyone help show me how this is done. I need to learn this for an upcoming midterm. Im using Python. ...

Deep recursive array of directory structure in PHP

I'm trying to put some folders on my hard-drive into an array. For instance, vacation pictures. Let's say we have this structure: Set 1 Item 1 of Set 1 Item 2 of Set 1 Item ... of Set 1 Set 2 Subset 1 of Set 2 Item 1 of Subset 1 of Set 2 Item ... of Subset 1 of Set 2 Subset 2 of Set 2 Random file, not a dir. Set 3 ... I want t...

My regex in python isn't recursing properly

I'm suppose to capture everything inside a tag and the next lines after it, but it's suppose to stop the next time it meets a bracket. What am i doing wrong? import re #regex regex = re.compile(r""" ^ # Must start in a newline first \[\b(.*)\b\] # Get what's enclosed in brackets \n...

How to use recursive table valued function in SQL SERVER 2005

I am making a split function in SQL Server 2005. I have already done it by using a while loop . But I am not happy with that. I want to do it using recursive function. I have already done it in C#. Now I am plotting the same in SQL SERVER 2005. But I am getting a compilation error. Here is my code ALTER FUNCTION [dbo].[fnSplit2] ( ...

CopyTo() to a directory that doesn't yet exist

I want to copy the file c:\a1\b2\c3\foo.txt to d:\a1\b2\c3\foo.txt. The subdirectories don't exist on the D drive, and if I try to do a direct CopyTo() I'll get an IO exception. I haven't been able to find any built-in c# function that does the dirty work of creating the missing directories. So I wrote this: FileInfo file = new FileInf...

recursive file search

I'm trying to figure out how to work this thing out .. For some reason, it ends at a certain point.. I'm not very good at recursion and I'm sure the problem lies somewhere there.. Also, even if I checked for cFileName != "..", it still shows up at the end, not sure why but the "." doesn't show up anymore.. void find_files( wstring wr...

GWT JsArray of self, recursive object array

I am building a tree structure which an object references itself in like so: public class ProjectObjectOL extends JavaScriptObject { protected ProjectObjectOL() { } public final native boolean getStatus() /*-{ return this.status; }-*/; public final native String getError() /*-{ return this.error_message; }-*/; pu...

Java Stack/Nest Count

Is there a quick way in java to get the nest/recurse level? I'm writing a function to make a list of Groups and their members. The members can be groups as well. It's possible that we could end up with a circular set of groups/member. I would like to stop at some arbitrary level. I know I could just keep a variable in a higher scope...

MySQL: How to find all IDs of children recursively?

I would like to get all IDs from children in a tree with MySQL only. I have a table like this: ID parent_id name 1 0 cat1 2 1 subcat1 3 2 sub-subcat1 4 2 sub-subcat2 5 0 cat2 Now I'm trying to get all child IDs for cat1 (2,3,4) recursively. Is there any way how to achieve that? Thanks for...

segfault after return 0;

I wrote a program to test my binary tree and when I run it, the program seems to crash (btree.exe has stopped working, Windows is checking for a solution ...). When I ran it through my debugger and placed the breakpoint on the function I suspect is causing it, destroy_tree(), it seemed to run as expected and returned back to the main fu...