• Advertisement
Sign in to follow this  

very tricky or am i just stupid?

This topic is 4303 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I am trying to write a code that will form part of a bigger code. I want to be able to enter these numbers (just random ones i chucked in): (1 2 3) (1 2) And then do this: (1 + 1) (2 + 2) (3 + 1) So I want to be able to apply the second list to the first list. And when the second list runs out, I want it to restart. But i'm unsure how? :( Please help.

Share this post


Link to post
Share on other sites
Advertisement
something like this

for int i = 0, j = 0; i < list1.size; i++, j++
if j >= list2.size
j = list2.size
list1[i] + list2[j]

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
homework?

Share this post


Link to post
Share on other sites
Quote:
Original post by vioxx_1
yes. and stuck on it.
any one know scheme?


I do, but how would doing your homework for you benefit you?

Share this post


Link to post
Share on other sites
We're not supposed to help with homework questions, which is just as well as I know nothing about Lisp or its descendants.

Share this post


Link to post
Share on other sites
We didn't get a solution for this one because it was a challenge question.
So there is no answer.
Thats why i want to know it
i've been trying to figure it out for 3 hours

Share this post


Link to post
Share on other sites
plus it is part of a bigger code i'm writing.
if i know this it will benefit the rest of the code i have written.
all i need to know is this and the rest will work.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
You're just stupid.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Quote:
Original post by smart_idiot
You're just nobody.


O RLY?

Share this post


Link to post
Share on other sites
Quote:
Original post by smart_idiot
Quote:
Original post by Anonymous Poster
Quote:
Original post by smart_idiot
You're just nobody.


O RLY?


YA RLY!


I couldn't find Wikimedia's hotlinking policy or this would've been in an <img> tag.

AP: Grow up. Posting kindergarden insults, behind a viel of anonymity, against a self admitted programming novice, trying to learn how to program, is what's stupid. And by "stupid" I mean disgusting and ill mannered. You were born allready knowing how to program in scheme? I think not.

vioxx_1: Homework help is mostly a no no around here, to prevent this forum being cluttered up by people who would use this forum as their own personal cheat sheet. On an online forum, it can be impossible to distinguish between someone wanting someone else to do their homework, and someone wanting to actually learn.

For the later, I suggest turning to your professor, your TAs, or your classmates. Given that all of the above will be focusing on your specific topic, they have the best chance of helping you. They're in a better position to gauge if you're cheating (and in a better position to report you if you are), or if you're trying to learn - in which case they'll be more able to cover in depth and detail what your class is focusing on, as it will be the same that they're focusing on.

That said, we can post nudges in the right direction if you explain your stumbling block. I don't know lisp, nevermind scheme (a dialect of lisp), but from what I can recall, the way to deal with your situation is to not modify the original list. You have a situation akin to:

inputa = (1 2 3)
inputb = (1 2)

And then creating combinations, by using car/cdr on those lists, loosing the original in the process. The key to going back to the origin (restarting) lies in not destroying the original.

[Edited by - MaulingMonkey on April 8, 2006 1:05:06 AM]

Share this post


Link to post
Share on other sites
The thing is is that I made up the list of numbers.
I just want to learn the process of recursion for another problem.
I'm actually converting characters into numbers and things like that.
So I need this process in order to be able to do it.
Is there any examples of this process using a different question?

Because all i want to know is how it works.

Share this post


Link to post
Share on other sites
Quote:
Original post by vioxx_1
The thing is is that I made up the list of numbers.
I just want to learn the process of recursion for another problem.
I'm actually converting characters into numbers and things like that.
So I need this process in order to be able to do it.
Is there any examples of this process using a different question?

Because all i want to know is how it works.


The "process of recursion" is very general, but usually it will look like this one of these two:

Tail call recursion:

(define (f ...)
(if ...
... ; Base case
(f ...))) ; Recursive case


Non-tail call recursion:

(define (f ...)
(if ...
... ; Base case
(g ... (f ...) ...))) ; Recursive case


Is this what you were asking for, or did you want a concrete example (really, pretty much all of the concrete examples will follow that pattern)?

Share this post


Link to post
Share on other sites

Hi,

You could do this quite easily using the modulus operator.

GCS584

Share this post


Link to post
Share on other sites
Quote:
Original post by gcs584

Hi,

You could do this quite easily using the modulus operator.

GCS584


What does modulus have to do with this? I don't see how using modulo will help iterate over a two lists and add each element.

Share this post


Link to post
Share on other sites
Quote:
Original post by Roboguy
Quote:
Original post by gcs584

Hi,

You could do this quite easily using the modulus operator.

GCS584


What does modulus have to do with this? I don't see how using modulo will help iterate over a two lists and add each element.


Well since I don't know Scheme, I made an assumption that an index for the retrieval of a value from the list could be specified.

GCS584

Share this post


Link to post
Share on other sites
Quote:
Original post by gcs584
Quote:
Original post by Roboguy
Quote:
Original post by gcs584

Hi,

You could do this quite easily using the modulus operator.

GCS584


What does modulus have to do with this? I don't see how using modulo will help iterate over a two lists and add each element.


Well since I don't know Scheme, I made an assumption that an index for the retrieval of a value from the list could be specified.

GCS584


Lists in Scheme are singly linked lists. The easiest (and most efficient) way to do this would be recursion over the linked lists, passing the tail of them to the recursive call.

Share this post


Link to post
Share on other sites
I assume that by 'tail', you mean the 'cdr' of the list, which is all but the first item. 'Tail' generally only refers to the last item.

Share this post


Link to post
Share on other sites
Quote:
Original post by iMalc
I assume that by 'tail', you mean the 'cdr' of the list, which is all but the first item. 'Tail' generally only refers to the last item.


Tail is commonly used to refer to what in Scheme is called the cdr in a linked list. I used the term because the person I was responding to does not know Scheme and would likely not know what the term "cdr" means.

Share this post


Link to post
Share on other sites
Since this is homework, I wont give you the full answer (I'd likely make an exception if you had posted nearly working source code).

You'll need (well needed for the solution I'm thinking of) to pass around 3 varibles through your recursive calls, the remaining part of the first list, the remaining part of the second list, and the entire second list. If that doesn't help, I'll give you another hint.

Share this post


Link to post
Share on other sites

This topic is 4303 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Guest
This topic is now closed to further replies.
Sign in to follow this  

  • Advertisement