recursion

Building a database driven menu with ASP.NET, JQuery and Suckerfish

Hello everyone, I'm attempting at creating a menu from a table using the Suckerfish css menu and Jquery. I'm using this as my reference: Suckerfish menu with ASP.NET and JQuery and I have it working with manually supplied links (much like in the article). Where I'm having issues is writing the recursive function to get the menu items f...

How do I detect circular logic or recursion in a custom expression evaluator?

I've written an experimental function evaluator that allows me to bind simple functions together such that when the variables change, all functions that rely on those variables (and the functions that rely on those functions, etc.) are updated simultaneously. The way I do this is instead of evaluating the function immediately as it's ent...

Recursion algorithm to generate sitemap

I've got a DataTable containing a sitemap hierarchy with the following columns: ItemId ParentId Name Url I need to generate a set of nested lists in HTML (left the anchor elements out for clarity): <ul> <li>Item 1</li> <li>Item 2</li> <ul> <li>Sub Item 1</li> <li class="current">Sub Item 2</li> </ul> <li>Item 3</li> ...

Reversing a Linked List in Java, recursively

I have been working on a Java project for a class for a while now. It is an implementation of a linked list (here called AddressList, containing simple nodes called ListNode). The catch is that everything would have to be done with recursive algorithms. I was able to do everything fine sans one method: public AddressList reverse() L...

how to write a recursive method in JavaScript using window.setTimeout()?

I'm writing a JavaSCript class that has a method that recursively calls itself. Scheduler.prototype.updateTimer = function () { document.write( this._currentTime ); this._currentTime -= 1000; // recursively calls itself this._updateUITimerHandler = window.setTimeout( arguments.callee , 1000 ); } Property description: ...

C stack overflow on Project Euler Problem 27

I just have started to learn Haskell and combine reading books and tutorials with solving problems from Project Euler. I have stuck on Problem 27 because I get "C stack overflow" error using this code: euler.hs divisors n = [x | x <- [1..n `div` 2], n `mod` x == 0] ++ [n] is_prime n = divisors n == [1, n] f a b = [n^2 + a * n + b | n ...

Python - Using __getattribute__ method

I want to override access to one variable in a class, but return all others normally. How do I accomplish this with __getattribute__? I tried the following (which should also illustrate what I'm trying to do) but I get a recursion error: class D(object): def __init__(self): self.test=20 self.test2=21 def __geta...

How can I execute a given function on every element of a complicated data structure in Perl?

I want to decode all the HTML entities in a complicated data structure. Basically I'm looking for a "super map()" function. Here's what I have so far: sub _html_decode { my $self = shift; my $ref = shift; if (ref($ref) eq "HASH") { $self->_html_decode_hash($ref) } if (ref($ref) eq "ARRAY") { $self->_...

Project Euler (P14): recursion problems

Hi I'm doing the Collatz sequence problem in project Euler (problem 14). My code works with numbers below 100000 but with numbers bigger I get stack over-flow error. Is there a way I can re-factor the code to use tail recursion, or prevent the stack overflow. The code is below: import java.util.*; public class v4 { // use a HashM...

Turn this recursive haskell function into a map call

This is my code: type HoraAtendimento = (String, Int, Int) htmlHAtendimento :: [HoraAtendimento] -> Html htmlHAtendimento [] = toHtml "" htmlHAtendimento ((da,hia,hfa):[]) = toHtml da +++ "feira " +++ show hia +++ "h - " +++ show hfa +++ "h" htmlHAtendimento ((da...

T-SQL Puzzler - Crawling Object Dependencies

This code involves a recursive Stored Procedure call and a "not so great" method of avoiding cursor name collision. In the end I don't care if it uses cursors or not. Just looking for the most elegant approach. I'm mainly going to use it as a simple method to track down Stored Proc hierarchies (without buying a product). I tried cursors ...

How can I break out of recursive find function once a specific file is found?

I'm using the File::Find module to traverse a directory tree. Once I find a specific file, I want to stop searching. How can I do that? find (\$processFile, $mydir); sub processFile() { if ($_ =~ /target/) { # How can I return from find here? } } ...

Implications of foldr vs. foldl (or foldl')

Firstly, Real World Haskell, which I am reading, says to never use foldl instead of foldl'. So I trust it. But I'm hazy on when to use foldr vs. foldl'. Though I can see the structure of how they work differently laid out in front of me, I'm too stupid to understand when "which is better." I guess it seems to me like it shouldn't real...

Classes Including Each Other in C++

Hello! I'm a C++ newbie, but I wasn't able to find the answer to this (most likely trivial) question online. I am having some trouble compiling some code where two classes include each other. To begin, should my #include statements go inside or outside of my macros? In practice, this hasn't seemed to matter. However, in this particu...

Recursive lambda expression to find the path(s) through a directed graph?

I need to find a path or paths down a complicated graph structure. The graph is built using something similar to this: class Node { public string Value { get; set;} public List<Node> Nodes { get; set;} public Node() { Nodes = new List<Node>(); } } What makes this complicated is that the nodes can referenc...

Data schema and query for polymorphic tree in SQL Server

I have run into this problem a couple of times in my career, and have never been very happy with the solution, and am presented with it again on a project I am doing in ASP.Net MVC, C#, SQL Server 2008: Imagine I have a Person type (class). I further have types Mother and Father that extend Person. Father and Mother are very similar: ...

Confusing [...] List in Python: What is it?

So I was writing up a simple binary tree in Python and came across [...] I don't believe this to be related to the Ellipsis object, more it seems to have something to do with an infinity loop (due to Python's shallow copy?). The source of this infinity loop and why it doesn't get expanded while expanding when accessed is something I'm c...

Mutual recursion -- can someone help explain how this code works?

I'm reading through "A Gentle Introduction to Haskell," and early on it uses this example, which works fine in GHC and horribly in my brain: initial = 0 next resp = resp process req = req+1 reqs = client initial resps resps = server reqs server (re...

How to iterate through a tree structure using a generator?

Hello people. I'm trying to figure out how to implement a function in a tree node which returns all its descendant leaves (whether direct or indirect). However, I don't want to pass a container in which the leaf nodes will be put recursively (the tree could be huge), instead I'd like to use a generator to iterate through the tree. I've ...

Is there a Ruby equivalent to Perl's Data::Rmap?

Perl's Data::Rmap allows you to recursively evaluate a BLOCK over a list of data structures (locally setting $_ to each element) and return the list composed of the results of such evaluations. $_ can be used to modify the elements. This is useful for iterating over things like nested hashes, or hierarchies of arrays of hashes and the l...