Develop a program which will merge the contents of two lists

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
Chris3103
Posts: 5
Joined: Tue Jan 07, 2014 9:22 pm

Develop a program which will merge the contents of two lists

Post by Chris3103 » Tue Jan 07, 2014 9:28 pm

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

FourthWorld
VIP Livecode Opensource Backer
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

Post by FourthWorld » Tue Jan 07, 2014 9:39 pm

Chris3103 wrote:You must...
Did you mean to write "I must...and could you please help?" The folks who share code here do so on a volunteer basis.

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

Klaus
Posts: 14199
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Develop a program which will merge the contents of two l

Post by Klaus » Tue Jan 07, 2014 9:42 pm

Hi Chris,

1. welcome to the forum! :D

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


Best

Klaus

townsend
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 430
Joined: Sun Feb 13, 2011 8:43 pm

Re: Develop a program which will merge the contents of two l

Post by townsend » Wed Jan 08, 2014 1:12 am

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.

MaxV
Posts: 1580
Joined: Tue May 28, 2013 2:20 pm
Contact:

Re: Develop a program which will merge the contents of two l

Post by MaxV » Wed Jan 08, 2014 10:09 am

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

Chris3103
Posts: 5
Joined: Tue Jan 07, 2014 9:22 pm

Re: Develop a program which will merge the contents of two l

Post by Chris3103 » Wed Jan 08, 2014 1:28 pm

yes it is part of an assignment....

Klaus
Posts: 14199
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Develop a program which will merge the contents of two l

Post by Klaus » Wed Jan 08, 2014 1:54 pm

Hi Chris,
Chris3103 wrote:yes it is part of an assignment....
this is an answer to what question? 8)

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

Chris3103
Posts: 5
Joined: Tue Jan 07, 2014 9:22 pm

Re: Develop a program which will merge the contents of two l

Post by Chris3103 » Wed Jan 08, 2014 2:12 pm

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

Klaus
Posts: 14199
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Develop a program which will merge the contents of two l

Post by Klaus » Wed Jan 08, 2014 2:34 pm

Hi Chris,
Chris3103 wrote:However, this is my first time on any forums like this so I was a bit not sure how to proceed.
well, politeness is in fact independet of the location 8)

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

FourthWorld
VIP Livecode Opensource Backer
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

Post by FourthWorld » Wed Jan 08, 2014 4:20 pm

Chris3103 wrote:yes it is part of an assignment....
Thank you, Chris.

The LiveCode forums have no policy against helping with homework, but some do. For example, the Ubuntu Forum posting guidelines include:
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 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.

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

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7393
Joined: Sat Apr 08, 2006 8:31 pm
Contact:

Re: Develop a program which will merge the contents of two l

Post by jacque » Wed Jan 08, 2014 7:04 pm

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

Chris3103
Posts: 5
Joined: Tue Jan 07, 2014 9:22 pm

Re: Develop a program which will merge the contents of two l

Post by Chris3103 » Fri Jan 10, 2014 2:49 pm

Jacque,

Yes it has to be exactly as outline.

Regards,

Chris

Klaus
Posts: 14199
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Develop a program which will merge the contents of two l

Post by Klaus » Fri Jan 10, 2014 2:59 pm

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?! 8)


Best

Klaus

Chris3103
Posts: 5
Joined: Tue Jan 07, 2014 9:22 pm

Re: Develop a program which will merge the contents of two l

Post by Chris3103 » Fri Jan 10, 2014 3:28 pm

Yes I have, will send it by Wed latest.

Post Reply