Develop a program which will merge the contents of two lists
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
Develop a program which will merge the contents of two lists
You must:
• develop the pseudocode
• desk-check
• test the program to ensure that it works for appropriate sets of data
Your list merge program should be a simple program which accepts whole number data for two lists which is entered by the user, and merges the two lists removing all duplicates.
Your program must take in the following inputs from the user:
• The number of values to be entered into each list (the array size).
• Each value to be stored in the arrays. Each list must not contain any duplicate numbers, so this must be checked for and prevented when adding to a list. However, a number which appears on the first list can still be added to the second list.
The two lists can be of different lengths, but cannot contain more than 50 elements. The program should work for whole numbers and should be able to handle a range of numbers from 0 to 50000. The program must check that the values entered fall within the valid ranges.
Merging two lists to remove duplicates is a multi-step process which involves searching over both arrays and adding the contents which appear in both arrays into an array to store the duplicates (in set theory, this is known as the Intersection). You should only place one copy of each duplicate number in this array. The numbers which only appear in one of the arrays but not both should be added to a separate new array. Finally, a new array should be created which is the merged list of both arrays: this list contains all the numbers from both lists with no duplicates.
Working through an example should help clarify this
We have two data sets of 10 numbers and want to find the duplicates and create a merged list. The data sets are below.
List A: 3, 4, 15, 27, 36, 76, 24, 35, 16, 51
List B: 7, 24, 19, 64, 121, 51, 12, 9, 15, 94
Looking at both lists, we can see that there are numbers which appear in both lists. If we step over List A and compare each number in turn to every number on List B, the first duplicate we find is 15, which is highlighted below:
List A: 3, 4, 15, 27, 36, 76, 24, 35, 16, 51
List B: 7, 24, 19, 64, 121, 51, 12, 9, 15, 94
The next duplicate number we find is 24:
List A: 3, 4, 15, 27, 36, 76, 24, 35, 16, 51
List B: 7, 24, 19, 64, 121, 51, 12, 9, 15, 94
The final duplicate number we find is 51:
List A: 3, 4, 15, 27, 36, 76, 24, 35, 16, 51
List B: 7, 24, 19, 64, 121, 51, 12, 9, 15, 94
We therefore add 15, 24, and 51 to the Intersection list.
The numbers that only appear on List A OR List B but not both get added to the ‘A OR B’ List.
The next step is to create the merged list. This is the combination of the Intersection List and the A OR B List.
Your program will need to perform the following operations:
• Accept user input for List A size and List B size, and values
• Perform data validation on user input
• Inform the user if any of the data is invalid.
• Prompt the user to re-enter the input while it is not valid
• Identify the duplicate numbers and add them to an Intersection list
• Identify the non-duplicate numbers and add them to an A OR B list
• Create a merged list
• Output the results
• develop the pseudocode
• desk-check
• test the program to ensure that it works for appropriate sets of data
Your list merge program should be a simple program which accepts whole number data for two lists which is entered by the user, and merges the two lists removing all duplicates.
Your program must take in the following inputs from the user:
• The number of values to be entered into each list (the array size).
• Each value to be stored in the arrays. Each list must not contain any duplicate numbers, so this must be checked for and prevented when adding to a list. However, a number which appears on the first list can still be added to the second list.
The two lists can be of different lengths, but cannot contain more than 50 elements. The program should work for whole numbers and should be able to handle a range of numbers from 0 to 50000. The program must check that the values entered fall within the valid ranges.
Merging two lists to remove duplicates is a multi-step process which involves searching over both arrays and adding the contents which appear in both arrays into an array to store the duplicates (in set theory, this is known as the Intersection). You should only place one copy of each duplicate number in this array. The numbers which only appear in one of the arrays but not both should be added to a separate new array. Finally, a new array should be created which is the merged list of both arrays: this list contains all the numbers from both lists with no duplicates.
Working through an example should help clarify this
We have two data sets of 10 numbers and want to find the duplicates and create a merged list. The data sets are below.
List A: 3, 4, 15, 27, 36, 76, 24, 35, 16, 51
List B: 7, 24, 19, 64, 121, 51, 12, 9, 15, 94
Looking at both lists, we can see that there are numbers which appear in both lists. If we step over List A and compare each number in turn to every number on List B, the first duplicate we find is 15, which is highlighted below:
List A: 3, 4, 15, 27, 36, 76, 24, 35, 16, 51
List B: 7, 24, 19, 64, 121, 51, 12, 9, 15, 94
The next duplicate number we find is 24:
List A: 3, 4, 15, 27, 36, 76, 24, 35, 16, 51
List B: 7, 24, 19, 64, 121, 51, 12, 9, 15, 94
The final duplicate number we find is 51:
List A: 3, 4, 15, 27, 36, 76, 24, 35, 16, 51
List B: 7, 24, 19, 64, 121, 51, 12, 9, 15, 94
We therefore add 15, 24, and 51 to the Intersection list.
The numbers that only appear on List A OR List B but not both get added to the ‘A OR B’ List.
The next step is to create the merged list. This is the combination of the Intersection List and the A OR B List.
Your program will need to perform the following operations:
• Accept user input for List A size and List B size, and values
• Perform data validation on user input
• Inform the user if any of the data is invalid.
• Prompt the user to re-enter the input while it is not valid
• Identify the duplicate numbers and add them to an Intersection list
• Identify the non-duplicate numbers and add them to an A OR B list
• Create a merged list
• Output the results
-
- VIP Livecode Opensource Backer
- Posts: 10052
- Joined: Sat Apr 08, 2006 7:05 am
- Contact:
Re: Develop a program which will merge the contents of two l
Did you mean to write "I must...and could you please help?" The folks who share code here do so on a volunteer basis.Chris3103 wrote:You must...
Also, this looks a bit like homework. Is it?
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
Re: Develop a program which will merge the contents of two l
Hi Chris,
1. welcome to the forum!
2.
I really don't feel like I need to actually
Best
Klaus
1. welcome to the forum!

2.
Come on, it would be good style to explain WHY we should need to!You must:
I really don't feel like I need to actually

Best
Klaus
Re: Develop a program which will merge the contents of two l
I am always faced with the choice" 1- write code that is most efficient, OR write code that is easy to understand. 95% of the time saving a 1/4 second is not a concern.
So, I'd dump all the values into a single variable with a carriage return. Then do a sort. And then finally, as I'm rebuilding the list in the needed format, toss out the duplicates, which should be very easy, since all duplicate values will be one after another.
So, I'd dump all the values into a single variable with a carriage return. Then do a sort. And then finally, as I'm rebuilding the list in the needed format, toss out the duplicates, which should be very easy, since all duplicate values will be one after another.
Re: Develop a program which will merge the contents of two l
This should work:
Code: Select all
put "3, 4, 15, 27, 36, 76, 24, 35, 16, 51 " into listA
put "7, 24, 19, 64, 121, 51, 12, 9, 15, 94" into listB
put empty into listOR
put empty into listinter
repeat for each item tItem in listA
put false into mycheck
repeat for each item t2Item in listB
if tItem = t2Item then
put true into mycheck
end if
end repeat
if mycheck is true then
put tItem & comma after listinter
else
put tItem & comma after listOR
end if
end repeat
repeat for each item tItem in listB
put false into mycheck
repeat for each item t2Item in listA
if titem = t2Item then
put true into mycheck
end if
end repeat
if mycheck is false then
put titem & comma after listOR
end if
end repeat
delete the last char of listOR
delete the last char of listinter
answer "The list OR is " & listOR
answer "The list of inter is " & listinter
Livecode Wiki: http://livecode.wikia.com
My blog: https://livecode-blogger.blogspot.com
To post code use this: http://tinyurl.com/ogp6d5w
My blog: https://livecode-blogger.blogspot.com
To post code use this: http://tinyurl.com/ogp6d5w
Re: Develop a program which will merge the contents of two l
yes it is part of an assignment....
Re: Develop a program which will merge the contents of two l
Hi Chris,
OK, just in case you did not get the message:
1. It would be polite to introduce yourself with your first posting in a new forum.
2. It is really a very bad introduction to start with "You must..." instead of e.g. "Hi, I'm ..."
We are always willing to help, but that also requires a BIT of respect and politeness
from your side, which you did not show yet!
Best
Klaus
this is an answer to what question?Chris3103 wrote:yes it is part of an assignment....

OK, just in case you did not get the message:
1. It would be polite to introduce yourself with your first posting in a new forum.
2. It is really a very bad introduction to start with "You must..." instead of e.g. "Hi, I'm ..."
We are always willing to help, but that also requires a BIT of respect and politeness
from your side, which you did not show yet!
Best
Klaus
Re: Develop a program which will merge the contents of two l
Hi Klaus,
Firstly, let me apologize for that. However, this is my first time on any forums like this so I was a bit not sure how to proceed.
My name is Chris. Yes, you are right. I should have introduced myself and ask for assistance. Instead I just typed what was required. Again I am sorry.
I am kindly seeking your assistance in doing the algorithm for this program and appreciate any assistance rendered.
Thanking you in advance.
Regards,
Chris
Firstly, let me apologize for that. However, this is my first time on any forums like this so I was a bit not sure how to proceed.
My name is Chris. Yes, you are right. I should have introduced myself and ask for assistance. Instead I just typed what was required. Again I am sorry.
I am kindly seeking your assistance in doing the algorithm for this program and appreciate any assistance rendered.
Thanking you in advance.
Regards,
Chris
Re: Develop a program which will merge the contents of two l
Hi Chris,
OK, this is a forum where Livecode users will help other Livecode users, but we will not write the complete code!
You already got some help, so it is up to you to work through it and TRY something by yourself, we will surely help
you when you get stuck.
I can recommend these stacks to get the basics of Livecode:
http://www.hyperactivesw.com/revscriptc ... ences.html
Best
Klaus
well, politeness is in fact independet of the locationChris3103 wrote:However, this is my first time on any forums like this so I was a bit not sure how to proceed.

OK, this is a forum where Livecode users will help other Livecode users, but we will not write the complete code!
You already got some help, so it is up to you to work through it and TRY something by yourself, we will surely help
you when you get stuck.
I can recommend these stacks to get the basics of Livecode:
http://www.hyperactivesw.com/revscriptc ... ences.html
Best
Klaus
-
- VIP Livecode Opensource Backer
- Posts: 10052
- Joined: Sat Apr 08, 2006 7:05 am
- Contact:
Re: Develop a program which will merge the contents of two l
Thank you, Chris.Chris3103 wrote:yes it is part of an assignment....
The LiveCode forums have no policy against helping with homework, but some do. For example, the Ubuntu Forum posting guidelines include:
The LiveCode forums are far more liberal than the Ubuntu Forums, and personally I'd like to keep it that way. Each has its place, but it's not like we're flooded with homework requests so I see no problem in lending a hand here, as long as we're not obviating the learning objectives of the lesson you've been asked to complete.While we are happy to serve as a resource for hints and for asking questions when you get stuck and need a little help, the Ubuntu Forums is not a homework service. Please do not post your homework assignments expecting someone else to do it for you. Any such threads will either be jailed or closed, and warnings or infractions may be issued.
The main thing to keep in mind with requests for help here is that everyone who contributes on these forums does so voluntarily. We're happy to help as time permits, but it's always nice to include a note like "Could you please help me with this?" as opposed to simply "You must...".
May I ask what the course is in which this assignment was given, and at what grade level? That'll help us find a good balance between helping with the code and also helping with the learning objectives of your class.
Thanks in advance for that, Chris, and welcome aboard. I hope you find LiveCode, and these forums, valuable in your learning and eventually in your career.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
Re: Develop a program which will merge the contents of two l
I'm wondering if the requirements are set in stone. LiveCode has much better ways to merge the two lists than the method described in the assignment.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com
HyperActive Software | http://www.hyperactivesw.com
Re: Develop a program which will merge the contents of two l
Jacque,
Yes it has to be exactly as outline.
Regards,
Chris
Yes it has to be exactly as outline.
Regards,
Chris
Re: Develop a program which will merge the contents of two l
Hi Chrisw,
I think its about time that you tell us a bit about the progress of your efforts in this respect so far!
You have started working on this, too, didn't you?!
Best
Klaus
I think its about time that you tell us a bit about the progress of your efforts in this respect so far!
You have started working on this, too, didn't you?!

Best
Klaus
Re: Develop a program which will merge the contents of two l
Yes I have, will send it by Wed latest.