Posted: Mon Sep 21, 2009 7:58 pm Post subject: 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!!!
Sponsor Sponsor
DemonWasp
Posted: Mon Sep 21, 2009 8:27 pm Post subject: RE:School Project Using Miranda
Well, first you should probably read the Wikipedia article on Miranda. It may also be helpful to find some more in-depth documentation, though that's beyond my helpfulness.
Next, you should probably figure out how you would solve the problem on paper - write down a bunch of numbers in two columns, then find all the numbers that occur in both lists yourself.
From your own pen-and-paper algorithm, determine what the computer needs to do to mimic you. This will require, at the very least, your two base lists, plus the list you use as the result.
If you run into specific difficulties, return here with a more specific request for help. Posts with error messages; in particular "I tried this using this code, and got thisresult" is a great way to get detailed, useful help.
OneOffDriveByPoster
Posted: Mon Sep 21, 2009 8:49 pm Post subject: Re: School Project Using Miranda
Are you allowed to use the built in definitions from the "standard environment"?
rar
Posted: Mon Sep 21, 2009 8:49 pm Post subject: 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
Posted: Mon Sep 21, 2009 8:50 pm Post subject: Re: School Project Using Miranda
rar @ Mon Sep 21, 2009 8:49 pm wrote:
Do you mean things like 'foldr'?
yes
rar
Posted: Mon Sep 21, 2009 8:52 pm Post subject: RE:School Project Using Miranda
yes definitely, for one of the other questions it was even required.
OneOffDriveByPoster
Posted: Mon Sep 21, 2009 9:06 pm Post subject: 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
Posted: Mon Sep 21, 2009 9:13 pm Post subject: 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?
Sponsor Sponsor
OneOffDriveByPoster
Posted: Mon Sep 21, 2009 9:19 pm Post subject: Re: RE:School Project Using Miranda
rar @ Mon Sep 21, 2009 9:13 pm wrote:
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
Posted: Mon Sep 21, 2009 9:20 pm Post subject: RE:School Project Using Miranda
Alright, is it easier not to?
OneOffDriveByPoster
Posted: Mon Sep 21, 2009 9:21 pm Post subject: 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
Posted: Mon Sep 21, 2009 9:23 pm Post subject: 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
Posted: Mon Sep 21, 2009 9:24 pm Post subject: Re: RE:School Project Using Miranda
rar @ Mon Sep 21, 2009 9:20 pm wrote:
Alright, is it easier not to?
What does "--" do with [7,7] -- [7]?
rar
Posted: Mon Sep 21, 2009 9:25 pm Post subject: Re: RE:School Project Using Miranda