Problem with recursion 
Author Message
 Problem with recursion

I was just wondering if anyone could help me. I am having trouble with one of
the functions that I am writing.  Basically this is what I am trying to do:
I have to write a program that in the lower left hand corner of the board
contains poison "X".  I have to choose a place to remove and then I remove
everything about and to the right.  For example, if I type in:
Quote:
> (bite)

List: (8 8 8 8 8 8 8 8 8 8)
Bite1: 5
Bite2: 6

O O O O
O O O O
O O O O
O O O O
O O O O
O O O O O O O O
O O O O O O O O
O O O O O O O O
O O O O O O O O
X O O O O O O O

The problem I am experienceing is when I try to take another bite out of the
new border (the 8x10 board with the bite taken at 5,6). for example if I try to
bite 3, 7 of the new board.  I should get
O O
O O
O O
O O
O O O O
O O O O O O O O
O O O O O O O O
O O O O O O O O
O O O O O O O O
X O O O O O O O
Here is my code, if anyone can help I would really appreciate it.  Thanks



Mon, 29 Apr 2002 03:00:00 GMT  
 Problem with recursion

Quote:

>I was just wondering if anyone could help me. I am having trouble with one of
>the functions that I am writing.

I think it's about time you went to your TA for some one-on-one help.  You
clearly need some help understanding some basic ideas, and this will be
much more efficient than posting lots of separate questions to the
newsgroup.

Quote:
>Here is my code, if anyone can help I would really appreciate it.  Thanks

You left out the code.  But if it's like the previous code you've posted,
it's probably pretty difficult to understand.

--

GTE Internetworking, Powered by BBN, Burlington, MA
*** DON'T SEND TECHNICAL QUESTIONS DIRECTLY TO ME, post them to newsgroups.
Please DON'T copy followups to me -- I'll assume it wasn't posted to the group.



Mon, 29 Apr 2002 03:00:00 GMT  
 Problem with recursion
Here is the code:
(define (bite)
  (let (
      (lis empty)
      (one empty)
      (two empty))
      (display "List: ")
      (set! lis (read))
      (display "Bite1: ")
      (set! one (read))
      (display "Bite2: ")
      (set! two (read))
    (newline)
    (display "Board after the bite")
    (newline)
    (column lis one two)))

(define (column lis one two)
  (do (
       (count1 (length lis) (- count1 1)))
    ((= count1 (- two 1)) (check lis one two count1))
   (row lis one)
    (newline)
   ))

(define (check lis one two count1)
  (do (
       (count6 count1 (- count6 1)))
    ((= 1 count6) (displayX lis))
    (fullrow lis)
    (newline)
    ))

(define (fullrow lis)
  (do (
       (count2 (first lis) (- count2 1)))
    ((= count2 1)(display "O "))
    (display "O ")
    ))

(define (row lis one)
  (do (
       (count2 2 (+ count2 1)))
    ((= count2 one) (display "O "))
    (display "O ")
    ))

(define (displayX lis)
  (display "X ")
  (do ((count3 (first lis) (- count3 1)))
      ((= count3 1))
    (display "O ")))

(define (displayO lis)
  (do (
       (count4 (first lis) (- count4 1)))
    ((= count4 2)(display "O "))
    (display "O ")))



Mon, 29 Apr 2002 03:00:00 GMT  
 Problem with recursion

Quote:

>Here is the code:

Your subject line mentions recursion, but I don't see any attempt at
recursion in your code.  You don't even save the resulting structure
anywhere, all you do is display it, so how do you intend to take a second
bite out of it?

As I said, you have some basic conceptual problems.  I'm assuming this is
for a college class, and your instructors should be there to help you with
this sort of thing.  Usenet is not an appropriate substitute for real
tutoring.

--

GTE Internetworking, Powered by BBN, Burlington, MA
*** DON'T SEND TECHNICAL QUESTIONS DIRECTLY TO ME, post them to newsgroups.
Please DON'T copy followups to me -- I'll assume it wasn't posted to the group.



Mon, 29 Apr 2002 03:00:00 GMT  
 Problem with recursion
then how would I do it?


Mon, 29 Apr 2002 03:00:00 GMT  
 Problem with recursion
can't I just call the function in bite?
do something like:
(column (column (8 8 8 8 8 8 8 8 8 8) 5 6) 3 7)


Mon, 29 Apr 2002 03:00:00 GMT  
 Problem with recursion

Quote:

>can't I just call the function in bite?
>do something like:
>(column (column (8 8 8 8 8 8 8 8 8 8) 5 6) 3 7)

No, because your column function doesn't return a useful value.  All your
functions do is print things.

--

GTE Internetworking, Powered by BBN, Burlington, MA
*** DON'T SEND TECHNICAL QUESTIONS DIRECTLY TO ME, post them to newsgroups.
Please DON'T copy followups to me -- I'll assume it wasn't posted to the group.



Mon, 29 Apr 2002 03:00:00 GMT  
 Problem with recursion

Quote:

> then how would I do it?

That's what your teacher or teaching assistant are for.  It's
important that they understand that you didn't understand the
lecture and knew you need help in this.  The code you posted
shows that you don't get it and it's their job to help you
understand the material.

If you'd posted here with a minor problem with a function we'd
probably have helped you, but understanding recursion is such
an important part of your course that you should have under-
stood it from your first lecture or from reading the course
book.  You can obviously write code when you know what you need.
It shouldn't be much of a problem for you to write the right
code with a little help from your teacher.

Simon.
--
http://www.hearsay.demon.co.uk | John Peel:
No junk email please.          |  [My daughter] has modelled herself on you.
                               | Courtney Love:
                               |  Oh, I'm so sorry.



Thu, 02 May 2002 03:00:00 GMT  
 Problem with recursion
Then how could I change my function so that I could use it over and over?


Sat, 04 May 2002 03:00:00 GMT  
 Problem with recursion

Quote:

>Then how could I change my function so that I could use it over and over?

You need to come up with a data representation, and then write your program
so that it computes the new representation from the old one and the slice
parameters.  A good representation for this might be a list of lists or a
vector of vectors.

Look, we're not going to write this for you.  Am I correct in guessing that
this is a class assignment?  This is what programming is all about:
designing data representations and the programs that manipulate them.

--

GTE Internetworking, Powered by BBN, Burlington, MA
*** DON'T SEND TECHNICAL QUESTIONS DIRECTLY TO ME, post them to newsgroups.
Please DON'T copy followups to me -- I'll assume it wasn't posted to the group.



Sat, 04 May 2002 03:00:00 GMT  
 
 [ 10 post ] 

 Relevant Pages 

1. Memory consumption problem with recursion

2. Problem with recursion

3. problem understanding recursion

4. Memory Problem with recursion

5. problems with recursion

6. RECURSION RECURSION RECURSION ... AAARRGGHHHH

7. Tail recursion and complete recursion?

8. loop problems (recursion)

9. tail recursion problem

10. problems with tree recursion.

11. problems with looping and recursion

12. I need help with recursion problem

 

 
Powered by phpBB® Forum Software