Computer Science Canada

recursion

Author:  nelson [ Sun Feb 01, 2004 10:27 pm ]
Post subject:  recursion

i'm trying to solve this problem

" Write a function using Recursion to display all anagrams of the word 'RECURSION' "

having trouble, i started though

code:


var str : string
str := "recursion"
var b : array 1 .. length (str) of int
var a : array 1 .. length (str) of string (1)

for i : 1 .. length (str)
    b (i) := 0
    a (i) := ""
end for


var temp : string
temp := str



proc er (n : int)


    for i : 1 .. length (str)

        a (n) := str (i)



        if n < length (str) then
            er (n + 1)
        else
            for k : 1 .. length (str)
                put a (k) ..
            end for
            put ""
        end if
    end for
end er


put length (str)
er (1)


heh -.,-;;;;;;;; help~

Author:  Paul [ Sun Feb 01, 2004 10:33 pm ]
Post subject: 

Isn't an anagram words made by rearranging the letters of the same word? correct me if Im wrong, Im not sure.

Author:  nelson [ Sun Feb 01, 2004 10:37 pm ]
Post subject: 

yup

Author:  Paul [ Sun Feb 01, 2004 10:39 pm ]
Post subject: 

Oh! At first I thought you wanted all the "real" words anagram, but you just want all possible combinations right? I think I'll work on that for a bit.

Author:  jonos [ Sun Feb 01, 2004 10:39 pm ]
Post subject: 

i think what you have is right, cause it does print out the whatchamacallits, but i've never used recursion (haven't been taught it in stupid compsci), so i wouldn't really know if you were doing it right.

Author:  nelson [ Sun Feb 01, 2004 10:40 pm ]
Post subject: 

haha if we wanted to do real words,
we would need a dictionary!

Author:  Paul [ Sun Feb 01, 2004 10:41 pm ]
Post subject: 

when I run it, theres alot of words with 4 "R"'s and there arn't 4 of them in Recursion.

Author:  nelson [ Sun Feb 01, 2004 10:41 pm ]
Post subject: 

but the program can only use two r

R ecu R sion

my program starts with 9 Rs

Author:  Paul [ Sun Feb 01, 2004 10:47 pm ]
Post subject: 

I see, well I'm sorry, but I can't help you right now, I have to go to bed, but I'll think on it whenver I have the chance. I dunno though, if it was me making it, I'd count the numbers of each letters, might be a stupid idea, Im too tired to think Confused

Author:  jonos [ Sun Feb 01, 2004 10:50 pm ]
Post subject: 

i didn't even notice that (the 4 rs), id help if i could cause i have lots of time, but i have no idea what recursion is.

Author:  Paul [ Sun Feb 01, 2004 10:51 pm ]
Post subject: 

It isn't recursion I think, hes trying to get anagrams (words that are made of the same letters) from the word "recursion"

Author:  nelson [ Sun Feb 01, 2004 10:53 pm ]
Post subject: 

but it's supposed to be recursion problem
so probably we hve to use recursion

Author:  jonos [ Sun Feb 01, 2004 10:58 pm ]
Post subject: 

could anyone explain to me what recursion is, then maybe i could have a go at it... thankyou Laughing

Author:  santabruzer [ Sun Feb 01, 2004 11:00 pm ]
Post subject: 

enjoy:
Quote:
A function that calls a simpler version of itself to arrive at a solution. For example, the factorial function (n!) can be defined recursively as (n(n-1)!), where (0!) is defined as equal to1. If a function calls another function that calls back the original function again, it is called mutual recursion; most ray-tracing programs fall into this general category.

Author:  jonos [ Sun Feb 01, 2004 11:17 pm ]
Post subject: 

uh, thanks for that definition, could yo uplease translate it into laymans terms Very Happy thanks for the definition, i think i have an idea of what it is


: