I have two lists. The numbers of elements in either list is variable. Here is an example to explain what is going in. In all cases the two lists are in ascending order.

{1,3,5,7}-->L1. {1,7}-->L2 // this is done.

{3,5}-->L3 //I need this work done.

Not clear? Ask questions Very Happy
I'm no calculator programmer, but couldn't you just look for and remove common values, so only uncommon ones remain?
I am trying to do that from within a program which is in operation. So, no I cannot do that, yet. That is the reason for the post. You dig?

Questions are always welcome! That helps clarify the problem for others. Very Happy
Do the lists need to keep their order?
I am not sure. When you get done you could give it one of these SortA(L2.

Forgive me for explaining, there was a time, not long ago ,that I did not know about Sorting in Ascending order.

As before, any question is welcome since it will assist in the convergence on the problem at hand. Very Happy
john massey wrote:

{1,3,5,7}-->L1. {1,7}-->L2 // this is done.

{3,5}-->L3 //I need this work done.



Code:
:0-->dim(L3
:For(N,1,dim(L1
:if not(prod(L2-L1(N):L1(N-->L3(dim(L3+1
:End


This should work. If I have some time, I'll see if I can get a better solution.
Here is my code with a little while statement to remind my self what I have interpreted your variables to be. I have had troubles with For(N. I changed it "W" because it was free. I further found that each time you use the program you need to set "W" to zero other wise it holds the exit value and the program will not run.

When I ran the program I got an invalid dim error at the end of the "If" statement. I knew if I was going to make a mistake, it would be there. Was it me or you?Very Happy


0→W
{1,3,5,7}→⌊TEMP4
0→dim(⌊TEMP6
For(W,1,dim(⌊TEMP4
If not(prod(⌊JONL1-⌊TEMP4(W):⌊TEMP4(W→⌊TEMP6(dim(⌊TEMP6+1
End
Output(1,1,⌊TEMP6
Pause
While 0:L3=TEMP6 L1=TEMP4 L2=JONL1 :End
DShiznit wrote:
I'm no calculator programmer, but couldn't you just look for and remove common values, so only uncommon ones remain?
Well, it's slightly more complicated than that, but yes. The steps:

A. The Easy Way
1. Merge the lists
2. Sort the result
3. Reduce strings of the same number to a single element

B. The Fast Way
1. Sort each list individually
2. Create a third list
3. Set a pointer at the beginning of each list
4. If the two elements of the two lists are the same, store one element to the new list; otherwise, store both elements, one from each input list
5. Repeat step 4, incrementing only the first pointer, until the element pointed in the first list is greater than or equal to that of the second list.
5. Repeat steps 4 and 5 until you reach the end of both lists.
Kerm,

Nice to see that the site is up. It was not up for me from 7 to 9 eastern time this AM.

Please note:

1.The post by rthprog above with a suggested solution
2. My response with the actual code
3. My translation From L1, L2 and L3 to my actual variables
4. A bug report on the if statement.

I have trouble understanding your post and ask the following questions:

5. Is rthprog's suggestion your "B"solution?
6. Is my bug report valid, since rthprog made a mistake?
7. Is my bug report invalid, since I made a mistake in translating rthprog's code in the "If" statement?
8. Since we have not heard from rthprog this AM, would you be kind enough, to resolve the mystery and tell me what to do?

Thanks in Advance.
Very Happy
Rthprog's solution is a simplified, vectorized example of my B solution; the magic there is the use of the prod( function to find zero'd elements. I believe that your translation, as reproduced below, is correct, such that LTEMP4 = L1, LJONL1 = L2, and LTEMP6=L3.


Code:
0→W
{1,3,5,7}→⌊TEMP4
0→dim(⌊TEMP6
For(W,1,dim(⌊TEMP4
If not(prod(⌊JONL1-⌊TEMP4(W):⌊TEMP4(W→⌊TEMP6(dim(⌊TEMP6+1
End
Output(1,1,⌊TEMP6
Pause


I ran your program and reproduced your error; the problem is a missing closing parenthesis on dim(, which rthprog also omitted. The long line should read:


Code:
If not(prod(⌊JONL1-⌊TEMP4(W):⌊TEMP4(W→⌊TEMP6(dim(⌊TEMP6)+1
or (shorter)
If not(prod(⌊JONL1-⌊TEMP4(W):⌊TEMP4(W→⌊TEMP6(1+dim(⌊TEMP6


I ran this program, which paused {1,7}, unfortunately not the solution we were seeking. Sad I looking at rthprog's code and confirmed that his keeps only duplicates rather than discarding all duplicates. Removing the "not" solves the problem:


Code:
0→W
{1,3,5,7}→⌊TEMP4
0→dim(⌊TEMP6
For(W,1,dim(⌊TEMP4
If prod(⌊JONL1-⌊TEMP4(W):⌊TEMP4(W→⌊TEMP6(dim(⌊TEMP6+1
End
Output(1,1,⌊TEMP6
Pause


I am concerned that if the lists were reversed: {1,7} in TEMP4 and {1,3,5,7} in JONL1, this method will not work, as it does not compare the lists symmetrically. Let me think about this problem.
Kerm,

Thank you very much for your help. Very Happy

Edit: Kerm,

Here is the code the program previously discussed called GOODFIX is implanted with explanation and question.


Code:
ClrHome
prgmGOODFIX//tested code so TEMP6 holds {3,5}.It is used to replace ⌊JONL1(J)≠0 because it only has values of {1,7} thus GOODFIX to the rescue.
0→J
For(J,1,dim(⌊OVER1
If ⌊OVER1(J)=0
End
If J=17:Stop
If ⌊JONL1(J)≠0 and ⌊JONL4(J)<4:⌊OVER1*(⌊OVER1≠J)→⌊OVER1
prgmSHOWSTUF
End


How do I select the values of {3,5} from TEMP6? I thought about a Statement like For,?,1,Dim(TEMP6. Then I get lost.
KermMartian wrote:

I ran your program and reproduced your error; the problem is a missing closing parenthesis on dim(, which rthprog also omitted. The long line should read:


Code:
If not(prod(⌊JONL1-⌊TEMP4(W):⌊TEMP4(W→⌊TEMP6(dim(⌊TEMP6)+1
or (shorter)
If not(prod(⌊JONL1-⌊TEMP4(W):⌊TEMP4(W→⌊TEMP6(1+dim(⌊TEMP6


I ran this program, which paused {1,7}, unfortunately not the solution we were seeking. Sad I looking at rthprog's code and confirmed that his keeps only duplicates rather than discarding all duplicates. Removing the "not" solves the problem[/code]


Oops, thanks for catching my mistake.

KermMartian wrote:
I am concerned that if the lists were reversed: {1,7} in TEMP4 and {1,3,5,7} in JONL1, this method will not work, as it does not compare the lists symmetrically. Let me think about this problem.


True... I'm trying to come up with a solution now.

By the way, 1) I'm not quite sure why you're storing 0 to "W", since the For( Loop will overwrite it anyways, and 2) You'll save a little bit of space if you use shorter names for your lists.
On the 1, matter. I have the following experience. When I run a program for the first iteration of a program everything is fine, if for example "If J=17" 17 is the exit criterion. That is ,one more than the loop count.

On the second iteration of the program J is still 17 and the program exits again. I find that if I set 0-->J everything works fine. When this first happened , I asked myself that is happening. I them ran a little test program with "TEXT(1,1,"Any message that you like" inside the loop. I made "For(I,1,100". Then I checked 'I" on the home screen, it was 101.

I have had this little nit twice in the last 2 days.
So this old man sets letter values to "0" on every occasion. Very Happy

On the 2. matter. I try to equate the name of the program with what the function does. With a program as complex as this and with a memory that is in the tank, it keeps me from completely loosing it.Smile

Let's take PUT0 for example. It takes the OVER1 with values like {1,3,5,7} and "PUTS0s in OVER1 so it now OVER1 holds {1,0,3,0,5,0,7,0,0,0,0,0,0,0,0,0}

I hope this clears up these two matters, If not fire away with questions.

I hope you find a solution for how to use TEMP6.

Code:
DelVar W


Do I win?
To find unique elements in L1 and L2 and output to L3, use this code (provided that "0" is not a unique element, and that no element is repeated within an individual list):


Code:
:augment(L1,L2-->L3
:L3*seq((1=sum(not(L3-L3(X)))),X,1,dim(L3))-->L3
:SortD(L3
:sum(L3!=0)-->dim(L3
:SortA(L3


The first two lines replace all common elements with "0", and the next 3 lines remove those 0s. The last line is optional; I don't know if it matters to John if they're in the right order.

@CDI
no, I meant "why clear W at all"?
I appreciate all your help. While I was working on my last post, you people were asking questions. Please, look up a ways to my last previous post and see if you agree with me.

For rthprog. I can see that you code is shorter and it will run faster. Let's concentrate on the question below and if we get the problem solved, I will make your changes in GOODFIX

Lets review the situation. We have created a list called TEMP6. It holds {3,5} Given that we use "For(?,1,Dim(TEMP6" the loop will run twice. The question mark indicates, I do not know what the call the loop counter. There will be two loops in this case.
john massey wrote:
We have created a list called TEMP6. It holds {3,5} Given that we use "For(?,1,Dim(TEMP6" the loop will run twice. The question mark indicates, I do not know what the call the loop counter. There will be two loops in this case.


You can use any single uppercase letter you want; it makes no difference. However, if this For-Loop is within another loop, then you must use a different variable. Does that answer your question?

What is this For loop going to accomplish?
After much study, I have boiled down the problem as follows:
You will need this first line of code if you run multiples


Code:
{1,0,3,0,5,0,7,0,0,0,0,0,0,0,0,0}→⌊OVER1
{3,5}→⌊TEMP6
SortD(⌊OVER1
sum((⌊OVER1≠0)→dim(⌊OVER1
SortA(⌊OVER1//The two lines of code above will result with ⌊OVER1 {1,3,5,7 tested and uses elsewhere.
For(J,1,dim(⌊TEMP6
If J=3:Stop// exit statement because TEMP6 holds 2 values.
If ⌊TEMP6(J) :⌊OVER1*(⌊OVER1≠J)→⌊OVER1//⌊TEMP6(J)// after the first pass the following are the correct answers
Output(1,1,"JA// JA
Output(1,4,J  // 3
Output(2,1,"OV// OV
Output(2,5,⌊OVER1// ⌊OVER1 {1,5,7}
End


Kerm's Edit: Jon, please use [code] tags; it makes your posts much more readable.
Kerm,
I do not know how to use CODE tags. A little torturing, please

{1,0,3,0,5,0,7,0,0,0,0,0,0,0,0,0}→⌊OVER1
ClrHome
{3,5}→⌊TEMP6
SortD(⌊OVER1
sum((⌊OVER1≠0)→dim(⌊OVER1
SortA(⌊OVER1
For(J,1,dim(⌊TEMP6
If J=3:Stop
If ⌊TEMP6(1):⌊OVER1*(⌊OVER1≠J)→⌊OVER1
Output(1,1,"JA
Output(1,5,J
Output(2,1,"OV
Output(2,5,⌊OVER1
Pause
ClrHome
End

Test results JA is 1 not 3
Ov is {0,3,5,7). That part is working since it removed the first element in the list. The question is " how do we recover the values of 3 & 5 from TEMP6
john massey wrote:
Kerm,
I do not know how to use CODE tags. A little torturing, please

{1,0,3,0,5,0,7,0,0,0,0,0,0,0,0,0}→⌊OVER1
ClrHome
{3,5}→⌊TEMP6
SortD(⌊OVER1
sum((⌊OVER1≠0)→dim(⌊OVER1
SortA(⌊OVER1
For(J,1,dim(⌊TEMP6
If ⌊TEMP6(1):⌊OVER1*(⌊OVER1≠J)→⌊OVER1
Output(1,1,"JA
Output(1,5,J
Output(2,1,"OV
Output(2,5,⌊OVER1
Pause
ClrHome
End

Test results JA is 1 not 3
Ov is {0,3,5,7). That part is working since it removed the first element in the list. The question is " how do we recover the values of 3 & 5 from TEMP6


Use the first two lines of rthprog's code. It works beautifully if you replase the = sign with a ≠ sign.


This is rthprog's code, it will return a list with 3 and 5 (i.e. the intersection of the lists)

Code:
{1,0,3,0,5,0,7,0,0,0,0,0,0,0,0,0→⌊OVER1
ClrHome
{3,5→⌊TEMP6
augment(LOver1,LTemp6-->LA
LA*seq((1≠sum(not(LA-LA(X)))),X,1,dim(LA))-->LA
SortD(LA
sum(LA!=0)-->dim(LA
SortA(LA


This is your code, it will return 1 and 7 (in case you need the numbers that are not in the intersection)

Code:
{1,0,3,0,5,0,7,0,0,0,0,0,0,0,0,0→⌊OVER1
ClrHome
{3,5→⌊TEMP6
For(J,1,dim(LOver1
LOver1*(LOver1≠LTemp6(J -> LOver1
SortD(LOver1
sum(LOver1≠0 -> dim(LOver1
SortA(LOver1
End


This is my solution that's based off of your code. It returns 3 and 5 (the intersection again)


Code:
{1,0,3,0,5,0,7,0,0,0,0,0,0,0,0,0}→⌊OVER1
ClrHome
{3,5}→⌊TEMP6
For(J,1,dim(LTemp6
LOver1=LTemp6(J
If not(sum(Ans
0 -> LTemp6(J
End
SortD(LTemp6
sum(LTemp6≠0 -> dim(LTemp6
SortA(LTemp6


I hope some of that helps. Rthprog's code already works great, so I'm not really adding anything to that.
  
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
Page 1 of 3
» All times are UTC - 5 Hours
 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

 

Advertisement