
-----------------------------------
rar
Mon Sep 21, 2009 7:58 pm

School Project Using Miranda
-----------------------------------
I don't think I've posted much here before except for in the Off-Topic forum. I signed up awhile ago in order to prepare in case I needed help.

Alright I'm in a first year class learning to use Miranda. There are reasons for starting with Miranda but I won't get into that.

I have an assignment and I've done all but this one program, and I was hoping someone could help me out...here is the question:

"(Make) A program which takes two lists of numbers and returns a list of numbers which are common to both input lists. HINT use the list operators (++ and/or --)"

Any help with this would be MUCH appreciated!!!

-----------------------------------
DemonWasp
Mon Sep 21, 2009 8:27 pm

RE:School Project Using Miranda
-----------------------------------
Well, first you should probably read the this using this code, and got thisresult" is a great way to get detailed, useful help.

-----------------------------------
OneOffDriveByPoster
Mon Sep 21, 2009 8:49 pm

Re: School Project Using Miranda
-----------------------------------
Are you allowed to use the built in definitions from the "standard environment"?

-----------------------------------
rar
Mon Sep 21, 2009 8:49 pm

Re: School Project Using Miranda
-----------------------------------
Are you allowed to use the built in definitions from the "standard environment"?

Do you mean things like 'foldr'?

-----------------------------------
OneOffDriveByPoster
Mon Sep 21, 2009 8:50 pm

Re: School Project Using Miranda
-----------------------------------
Do you mean things like 'foldr'?yes

-----------------------------------
rar
Mon Sep 21, 2009 8:52 pm

RE:School Project Using Miranda
-----------------------------------
yes definitely, for one of the other questions it was even required.

-----------------------------------
OneOffDriveByPoster
Mon Sep 21, 2009 9:06 pm

Re: School Project Using Miranda
-----------------------------------
I suppose from your description, you need to produce a function which takes two lists of numbers and returns one.
The first step is to figure out what to do if one or both of the lists are empty.  What is common between the two lists then?

-----------------------------------
rar
Mon Sep 21, 2009 9:13 pm

RE:School Project Using Miranda
-----------------------------------
Alright, but how do you figure out which numbers are common between the 2 lists? Some advice I received from someone in my class:
"what i did was
 sorted both lists, then i removed the duplicate elements in each list
 so that means each list only consisted of unique elements
 and then
 you check"

Does this have any merit?

-----------------------------------
OneOffDriveByPoster
Mon Sep 21, 2009 9:19 pm

Re: RE:School Project Using Miranda
-----------------------------------
Alright, but how do you figure out which numbers are common between the 2 lists? Some advice I received from someone in my class:
"what i did was
 sorted both lists, then i removed the duplicate elements in each list
 so that means each list only consisted of unique elements
 and then
 you check"

Does this have any merit?You can use sorting, but you do not have to.

-----------------------------------
rar
Mon Sep 21, 2009 9:20 pm

RE:School Project Using Miranda
-----------------------------------
Alright, is it easier not to?

-----------------------------------
OneOffDriveByPoster
Mon Sep 21, 2009 9:21 pm

Re: School Project Using Miranda
-----------------------------------
The first step is to figure out what to do if one or both of the lists are empty.Hopefully, you have a solution that works when at least one list is empty.

Now what if you have a one-element list and another non-empty list?

A two-element list and another non-empty list?  Can you use the one-element solution to help solve the two-element case?

Can you use (no matter how trivially) the empty-lists solution to help solve the one-element case?

Can you generalize?  For example, in the one-element case, the element you have in the one-element list to work with is also the first element.
To reach the one-element case from the two-element case, you did something with one of the two elements.  What if you chose to do something with the first element?

In Miranda, it seems the "--" operation is more powerful than usual.

-----------------------------------
rar
Mon Sep 21, 2009 9:23 pm

RE:School Project Using Miranda
-----------------------------------
I'm assuming generalizing would be easiest anyway, but yes I believe that's the intent of the program.

-----------------------------------
OneOffDriveByPoster
Mon Sep 21, 2009 9:24 pm

Re: RE:School Project Using Miranda
-----------------------------------
Alright, is it easier not to?What does "--" do with [7,7] -- [7]?

-----------------------------------
rar
Mon Sep 21, 2009 9:25 pm

Re: RE:School Project Using Miranda
-----------------------------------
Alright, is it easier not to?What does "--" do with 

[7]?

-----------------------------------
DtY
Mon Sep 21, 2009 9:28 pm

RE:School Project Using Miranda
-----------------------------------
If nothing else works, loop (or recurse?) over each item in the first list, and check if it's in the second.

-----------------------------------
OneOffDriveByPoster
Mon Sep 21, 2009 9:34 pm

Re: RE:School Project Using Miranda
-----------------------------------
What does "--" do with I think using "--" is overkill if you are going to sort anyway.  But sorting is a good way to do this.  Consider:[code]head :: [num] -> num
head (b:c) = b

tail :: [num] -> [num]
tail (b:c) = c[/code]

-----------------------------------
rar
Tue Sep 22, 2009 10:50 am

RE:School Project Using Miranda
-----------------------------------
[code]program x y = x -- (x -- y)[/code]

-_- Feel like an idiot now  :|  It's so simple!

Thanks for the help!

-----------------------------------
Alexmula
Tue Sep 22, 2009 5:05 pm

RE:School Project Using Miranda
-----------------------------------
some1 from uWindsor :D
