Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-

RECURSION MASTERY CHALLENGE

Name: Anonymous 2012-02-02 22:53

THE CHALLENGE:
Create a program that calls a recursive function which calls a recursive function which calls the original recursive function.
# The program must terminate.
Bonus points for doing something cool! ! !

For example, a program that consists of two functions, A and B.
Function A would be a recursive function that called itself. Function A also calls Function B.
Function B would be a recursive function that called itself. Function B also calls Function A.

Name: Anonymous 2012-02-02 22:56

Need heuristics for A* search for finding optimal path through a pacman maze.  No ghosts, just food.  Help pacman find the shortest path to get all food.  Thoughts?

Name: Anonymous 2012-02-02 22:56

Need heuristics for A* search for finding optimal path through a pacman maze.  No ghosts, just food.  Help pacman find the shortest path to get all food.  Thoughts?

Name: Anonymous 2012-02-02 23:02

>>4

Name: Anonymous 2012-02-02 23:03

Every program will terminate at the heat death of the universe

Name: Anonymous 2012-02-02 23:15

Name: Anonymous 2012-02-02 23:22


#include <iostream>
int term = 1;
int a () {
if (term == 2)
return 0;
b();
};

int b() {
c();
};

int c() {
term = 2;
a();
};

int main() {
a();

}

Name: Anonymous 2012-02-02 23:34


multi A(0, $n) { $n +1 }
multi A($m, 0) { A( $m -1, 1 ) }
multi A($m, $n) { A($m -1, A($m, $n -1)) }

say A(3,2);

Name: Anonymous 2012-02-03 2:09

(define (eval exp env)
  ...)

(define (apply proc args)
  ...)

Name: Anonymous 2012-02-03 2:13


int is_even(int num)
{
    if (num == 0)
        return 1;
    else
        return is_odd(num - 1);
}

int is_odd(int num)
{
    if (num == 0)
        return 0;
    else
        return is_even(num - 1);
}

Name: Anonymous 2012-02-03 9:04

I like the backwards-first graph search algorithm. It only uses one function, but it is said to recurse O(n^2) deep on certain n-vertex graphs.

from collections import defaultdict
labels = defaultdict(lambda:0)

neighbours = {
        0 : [1, 5],
        1 : [0, 6, 2],
        2 : [1, 3],
        3 : [2, 4],
        4 : [3, 5],
        5 : [4, 1],
        6 : [1],
        }

def bwfs(v, i = 1, d = 0):
    print d, i, v, labels[v]
    if not labels[v]: yield v
    labels[v] = i
    for u in neighbours[v]:
        if 0 < labels[u] < i:
            for r in bwfs(u, i, d + 1):
                yield r
    for u in neighbours[v]:
        if labels[u] == 0:
            for r in bwfs(u, i + 1, d + 1):
                yield r
           
print list(bwfs(0))

Name: Anonymous 2012-02-03 9:11

int b(int i);
int a(int i){
++i;
return i % 2 == 0 ? a(i) : b(i);
}
int b(int i){
++i;
return i % 3 == 0 ? a(i) : (i % 3 == 1 b(i) : 0);
}

Name: Anonymous 2012-02-03 9:14

```````siisk.xisii

Name: Anonymous 2012-02-03 10:46

>>5
God will punish you! THE UNIVERSE IS INFINITE! Jews told me!

Don't change these.
Name: Email:
Entire Thread Thread List