COMBINING TWO LISTS
Forum » Programming Help / TI-83 Programming » COMBINING TWO LISTS
Started by: john masseyjohn massey
On: 1257349632|%e %b %Y, %H:%M %Z|agohover
Number of posts: 39
rss icon RSS: New posts
Summary:
I have two lists which do not contain the same numbers and I want to combine them.
COMBINING TWO LISTS
john masseyjohn massey 1257349632|%e %b %Y, %H:%M %Z|agohover

I have two lists and I want to combine them. The two lists have no common numbers.

Example
{1 2 3}>L1
{4 6 8}
>L2
combined list
{1 2 3 4 6 8}—>L3

Thanks in advance

john

unfold COMBINING TWO LISTS by john masseyjohn massey, 1257349632|%e %b %Y, %H:%M %Z|agohover
Re: COMBINING TWO LISTS
 brt93yoda brt93yoda 1257360425|%e %b %Y, %H:%M %Z|agohover

I made it so the lists combine into L3, but you can change it so they combine into any list.

{1,2,3}->L1
{4,6,8}->L2
dim( L1+1->A  
L1->L3
For(X,1,dim(L2
L2(x)->L3(A)
A+1->A
End
L3
last edited on 1257360462|%e %b %Y, %H:%M %Z|agohover by brt93yoda + show more
unfold Re: COMBINING TWO LISTS by  brt93yoda brt93yoda, 1257360425|%e %b %Y, %H:%M %Z|agohover
Re: COMBINING TWO LISTS
bxsciencerbxsciencer 1257369686|%e %b %Y, %H:%M %Z|agohover

why not

augment(L₁, L₂) →L₃

?

Visit Calccrypto for info on crypto

unfold Re: COMBINING TWO LISTS by bxsciencerbxsciencer, 1257369686|%e %b %Y, %H:%M %Z|agohover
Re: COMBINING TWO LISTS
Timothy FosterTimothy Foster 1257374111|%e %b %Y, %H:%M %Z|agohover

As bxsciencer mentioned, augment( will combine any two lists into one lists.

unfold Re: COMBINING TWO LISTS by Timothy FosterTimothy Foster, 1257374111|%e %b %Y, %H:%M %Z|agohover
Re: COMBINING TWO LISTS
john masseyjohn massey 1257374085|%e %b %Y, %H:%M %Z|agohover

brt93yoda,

I tried you code. It worked fine but one of the assumptions I made was incorrect. There are duplicates in the completed lists. I verified that it actually happens. That is, it was not a coding error on your part.:-) Also the numbers need to be in ascending order. I guess ascending is correct, being old and very forgetful, I am not sure. So just in case 1 2 3 4 5 …

bxsciencer,

I tried the augment. After I had run the program, on the home screen. I assumed the values for the lists stayed the same as they were in the program. However I did not get a correct answer.

unfold Re: COMBINING TWO LISTS by john masseyjohn massey, 1257374085|%e %b %Y, %H:%M %Z|agohover
Re: COMBINING TWO LISTS
john masseyjohn massey 1257374388|%e %b %Y, %H:%M %Z|agohover

Well I will try the augment in the program. I the meantime, how do you suggest that we deal with duplicates and ascending order?

unfold Re: COMBINING TWO LISTS by john masseyjohn massey, 1257374388|%e %b %Y, %H:%M %Z|agohover
Re: COMBINING TWO LISTS
ztrumpetztrumpet 1257375757|%e %b %Y, %H:%M %Z|agohover

Use the SortA( command to sort lists.

To remove duplicates:
Input and output in Ans. Uses L3
:Ans→L3
:{Ans(1
:For(A,1,dim(L3))
:If min(Ans≠L3(A
:augment(Ans,{L3(A
:End


Projects (in order of priority) : Gravity Dude 30% Escape 15%

United Ti: http://www.unitedti.org/index.php?act=idx

last edited on 1257375919|%e %b %Y, %H:%M %Z|agohover by ztrumpet + show more
unfold Re: COMBINING TWO LISTS by ztrumpetztrumpet, 1257375757|%e %b %Y, %H:%M %Z|agohover
Re: COMBINING TWO LISTS
 brt93yoda brt93yoda 1257532227|%e %b %Y, %H:%M %Z|agohover

I never knew the SortA( and Augment commands

unfold Re: COMBINING TWO LISTS by  brt93yoda brt93yoda, 1257532227|%e %b %Y, %H:%M %Z|agohover
Re: COMBINING TWO LISTS
john masseyjohn massey 1257382168|%e %b %Y, %H:%M %Z|agohover

It is not working. Perhaps I have misinterpreted something. The code looks something like it did after the first statement in the code below. Here is the code:

augment(⌊JONL1,⌊JONL5)→⌊JONL3
SortA(⌊JONL3
Ans→⌊JONL3
{Ans(1
For(A,1,dim(⌊JONL3))
If min(Ans≠⌊JONL3(A
augment(Ans,{⌊JONL3(A
End

unfold Re: COMBINING TWO LISTS by john masseyjohn massey, 1257382168|%e %b %Y, %H:%M %Z|agohover
Re: COMBINING TWO LISTS
WeregooseWeregoose 1257393928|%e %b %Y, %H:%M %Z|agohover

SortA( alters the list, but it doesn't return a result that can be recalled with Ans. The line below the sort is taking the line above the sort and storing it again to JONL3, which means that you no longer have a sorted list when you are taking the first element.

unfold Re: COMBINING TWO LISTS by WeregooseWeregoose, 1257393928|%e %b %Y, %H:%M %Z|agohover
Re: COMBINING TWO LISTS
john masseyjohn massey 1257419454|%e %b %Y, %H:%M %Z|agohover

Hi Weregoose,
Nice to here from you again.

Well, How do I fix this bad boy. If I understand you correctly I should move the SortA command down to after the End statement. Is that correct?

Please advise

john

unfold Re: COMBINING TWO LISTS by john masseyjohn massey, 1257419454|%e %b %Y, %H:%M %Z|agohover
Re: COMBINING TWO LISTS
graphmasturgraphmastur 1257423604|%e %b %Y, %H:%M %Z|agohover

Just remove the line after SortA(.


"But sanctify the Lord God in your hearts, and always be ready to give a defense to everyone who asks you a reason for the hope that is in you, with meekness and fear;" ~ 1 Peter 3:16

unfold Re: COMBINING TWO LISTS by graphmasturgraphmastur, 1257423604|%e %b %Y, %H:%M %Z|agohover
Re: COMBINING TWO LISTS
WeregooseWeregoose 1257430880|%e %b %Y, %H:%M %Z|agohover

Either solution will work.

unfold Re: COMBINING TWO LISTS by WeregooseWeregoose, 1257430880|%e %b %Y, %H:%M %Z|agohover
Re: COMBINING TWO LISTS
john masseyjohn massey 1257431677|%e %b %Y, %H:%M %Z|agohover

thanks for your quick responses from the master programmers!

The master tester is off to test.

john

unfold Re: COMBINING TWO LISTS by john masseyjohn massey, 1257431677|%e %b %Y, %H:%M %Z|agohover
Re: COMBINING TWO LISTS
john masseyjohn massey 1257471511|%e %b %Y, %H:%M %Z|agohover

I can see the light at the end of the tunnel. I have the two lists combined and in ascending order. There is however a small nit. I have duplicates in the list. I just need one of you master programmers to whip out a solution.:-)

Thanks in advance!

john

unfold Re: COMBINING TWO LISTS by john masseyjohn massey, 1257471511|%e %b %Y, %H:%M %Z|agohover
Re: COMBINING TWO LISTS
bxsciencerbxsciencer 1257474429|%e %b %Y, %H:%M %Z|agohover

I think this works:

For(X,1,dim(⌊JONL3)-1
If ⌊JONL3(X)= ⌊JONL3(X+1)
0→⌊JONL3(X)
End
SortD(⌊JONL3
While ⌊JONL3(dim(⌊JONL3)) = 0
dim(⌊JONL3)-1→⌊JONL3
End
SortA(⌊JONL3

Visit Calccrypto for info on crypto

unfold Re: COMBINING TWO LISTS by bxsciencerbxsciencer, 1257474429|%e %b %Y, %H:%M %Z|agohover
Re: COMBINING TWO LISTS
john masseyjohn massey 1257508889|%e %b %Y, %H:%M %Z|agohover

I get an invalid dim error on the SortD line of code. I studied that command very closely and decided I did not need to replace any commands, as I had earlier discussed.

What say you?

john

unfold Re: COMBINING TWO LISTS by john masseyjohn massey, 1257508889|%e %b %Y, %H:%M %Z|agohover
Re: COMBINING TWO LISTS
Timothy FosterTimothy Foster 1257656557|%e %b %Y, %H:%M %Z|agohover

Try this code?

For(A,dim(ΔList(LJONL3)),1,-1
ΔList(LJONL3
If not(Ans(A
augment(seq(LJONL3(I),I,1,A-1),seq(LJONL3(I),I,A+1,dim(LJONL3→LJONL3
End


If LJONL3 is in ascending order, this should rid it of duplicates. This is kind of a brute force method, but it seems to work UNLESS the first set of numbers are duplicates. But if you store a zero as the first element of the list prior to running this code (unless you expect zeroes to be first in the list, therefore a number like -435 might be better) and deleting it afterward.
last edited on 1257656895|%e %b %Y, %H:%M %Z|agohover by Timothy Foster + show more
unfold Re: COMBINING TWO LISTS by Timothy FosterTimothy Foster, 1257656557|%e %b %Y, %H:%M %Z|agohover
Re: COMBINING TWO LISTS
john masseyjohn massey 1257686534|%e %b %Y, %H:%M %Z|agohover

In the first line of code the compiler hangs up just after the JONL3.

I can initialize JOHNL3 with a zero. Is there a way to remove the zero with code while still in the program, rather than doing it manually? I have no idea how to remove a zero from a list from in a running program

unfold Re: COMBINING TWO LISTS by john masseyjohn massey, 1257686534|%e %b %Y, %H:%M %Z|agohover
Re: COMBINING TWO LISTS
Timothy FosterTimothy Foster 1257713392|%e %b %Y, %H:%M %Z|agohover

I have no idea how to remove a zero from a list from in a running program

Use the code:

:seq(∟JONL3(I),I,2,dim(∟JONL3→∟JONL3

This creates a "new" list using all the numbers in ∟JONL3 except the first.
unfold Re: COMBINING TWO LISTS by Timothy FosterTimothy Foster, 1257713392|%e %b %Y, %H:%M %Z|agohover
Re: COMBINING TWO LISTS
john masseyjohn massey 1257769695|%e %b %Y, %H:%M %Z|agohover

Hi Timothy,
I have learned to design a small program that will test all the code that I was given instead of running this code in a program. I did this. You can see that I expected 1,2,3,4,6,10. I got however 2,3,4,2,3,4,6,8,10. I have gotten lost somehow. Please advise. Code follows:

ClrDraw
{0}→⌊JONL3
{1,2,3,4}→⌊JONL1
{2,3,4,6,8,10}→⌊JONL5
augment(⌊JONL1,⌊JONL5)→⌊JONL3
For(A,dim(ΔList(⌊JONL3)),1,–1
ΔList(⌊JONL3
If not(Ans(A
augment(seq(⌊JONL3(I),I,1,A-1),seq(⌊JONL3(I),I,A+1,dim(⌊JONL3→⌊JONL3
End
seq(⌊JONL3(I),I,2,dim(⌊JONL3→⌊JONL3
Output(1,1,⌊JONL3
Pause

unfold Re: COMBINING TWO LISTS by john masseyjohn massey, 1257769695|%e %b %Y, %H:%M %Z|agohover
Re: COMBINING TWO LISTS
Timothy FosterTimothy Foster 1257772462|%e %b %Y, %H:%M %Z|agohover

Your list wasn't in ascending order. Put a SortA(∟JONL3 after the first augment line and it should work. Also, put this just before the For line:

augment({0},LJONL3

Your entire code will look as follows:

ClrDraw
{1,2,3,4→LJONL1
{2,3,4,6,8,10→LJONL5
augment(LJONL1,LJONL5→LJONL3
SortA(LJONL3
augment({0},LJONL3
For(A,dim(ΔList(LJONL3)),1,-1
ΔList(LJONL3
If not(Ans(A
augment(seq(LJONL3(I),I,1,A-1),seq(LJONL3(I),I,A+1,dim(LJONL3→LJONL3
End
seq(LJONL3(I),I,2,dim(LJONL3→LJONL3
Output(1,1,LJONL3
Pause

unfold Re: COMBINING TWO LISTS by Timothy FosterTimothy Foster, 1257772462|%e %b %Y, %H:%M %Z|agohover
Re: COMBINING TWO LISTS
ztrumpetztrumpet 1257778192|%e %b %Y, %H:%M %Z|agohover

Wouldn't it be better if the last two lines were

:Pause LJONL3


Projects (in order of priority) : Gravity Dude 30% Escape 15%

United Ti: http://www.unitedti.org/index.php?act=idx

unfold Re: COMBINING TWO LISTS by ztrumpetztrumpet, 1257778192|%e %b %Y, %H:%M %Z|agohover
Re: COMBINING TWO LISTS
Timothy FosterTimothy Foster 1257782664|%e %b %Y, %H:%M %Z|agohover

You could, though if you want the list to wrap the screen, it is better to use the Output( command. Depends on what you want the output to look like.

unfold Re: COMBINING TWO LISTS by Timothy FosterTimothy Foster, 1257782664|%e %b %Y, %H:%M %Z|agohover
Re: COMBINING TWO LISTS
john masseyjohn massey 1257784013|%e %b %Y, %H:%M %Z|agohover

For Timothy,

Everything is just fine. I did need to replace all your large Ls with my little "Ls", you had me there for a little while :-) Just one nit. You can see from the values of JONL1 that I included a "1" just to make sure that we were not going to deal with loosing the "1" in the list, as we had discussed earlier. Well we did, there is no "1"in JONL3.

For ztrumpet,

I closed the way I did because I wanted to see JONL3 on the screen and I thought I would not loose it while the program was waiting for the good old Key 105.

unfold Re: COMBINING TWO LISTS by john masseyjohn massey, 1257784013|%e %b %Y, %H:%M %Z|agohover
Re: COMBINING TWO LISTS
Timothy FosterTimothy Foster 1257796911|%e %b %Y, %H:%M %Z|agohover

Oh, sorry, I had a typo…

Change:

augment({0},∟JONL3

to
augment({0},∟JONL3→∟JONL3

That's why the 1 is disappearing because the 0 wasn't picked up…

unfold Re: COMBINING TWO LISTS by Timothy FosterTimothy Foster, 1257796911|%e %b %Y, %H:%M %Z|agohover
Re: COMBINING TWO LISTS
john masseyjohn massey 1257798349|%e %b %Y, %H:%M %Z|agohover

Hi Timothy,

The change worked wonderfully!

Thank you very much. I continue to learn from you!

unfold Re: COMBINING TWO LISTS by john masseyjohn massey, 1257798349|%e %b %Y, %H:%M %Z|agohover
Re: COMBINING TWO LISTS
john masseyjohn massey 1257809531|%e %b %Y, %H:%M %Z|agohover

Hi Timothy,

There appears to be a problem when either JONL1 or JONL5: JONL1 and JONL5 have no values.

If JONL1 is empty then JONL5—>JONL3 and we do not need the program. I discovered this when there were no errors in 16 problems and I got a DIM error when the code entered my program called SUMED.

Of course, a Child could have all reaction times that are <3 seconds. But if just 1 reaction time is>2, JONL5 has a value. Perhaps one child in 100 could do it. I sure cannot do it!

Your record has been wonderful at solving problems. So I guess you can figure out something. :-)

john

unfold Re: COMBINING TWO LISTS by john masseyjohn massey, 1257809531|%e %b %Y, %H:%M %Z|agohover
Re: COMBINING TWO LISTS
john masseyjohn massey 1257817903|%e %b %Y, %H:%M %Z|agohover

On second though, you should see the code that surrounds the SUMED program. To pass from this program the child is allowed 1 error and have a second sum(JONL4<40. That should get to the code in the Else bucket. That with get to the two Output massages.
The then Bucket holds all the code that needs to be performed upon child failure.
The OPPS message is to me know that the child has failed.
The next two lines make the transfer and then display OVER The pause statement just lets me see that everything is OK before we head off to the REDUE2.

prgmSUMED
If E>1 or sum(⌊JONL4)>40
Then
Output(1,1,"OPPS
⌊JONL3→⌊OVER
Output(1,1,⌊OVER
Pause
prgmREDUE2
Else
Output(1,1,"READY FOR MORE
Output(2,1,"MATH FUN?

unfold Re: COMBINING TWO LISTS by john masseyjohn massey, 1257817903|%e %b %Y, %H:%M %Z|agohover
Re: COMBINING TWO LISTS
ztrumpetztrumpet 1257818880|%e %b %Y, %H:%M %Z|agohover

It's probably a good idea to put an End at the end of that program.


Projects (in order of priority) : Gravity Dude 30% Escape 15%

United Ti: http://www.unitedti.org/index.php?act=idx

unfold Re: COMBINING TWO LISTS by ztrumpetztrumpet, 1257818880|%e %b %Y, %H:%M %Z|agohover
Re: COMBINING TWO LISTS
john masseyjohn massey 1257827181|%e %b %Y, %H:%M %Z|agohover

For ztrumpet,
I agree

For Timothy,

I think this truth table is correct
If dim(JONL1 ≠0 and dim(JONL5 ≠0:prgmSUMED
If dim(JONL1=0 and dim(JONL5≠0:JONL5>JONL3
If dim(JONL1=0 and dim(JONL5=0:exit program
If dim(JONL1≠0 and dim(JONL5=0:JONL1
>JONL3

john

unfold Re: COMBINING TWO LISTS by john masseyjohn massey, 1257827181|%e %b %Y, %H:%M %Z|agohover
Re: COMBINING TWO LISTS
john masseyjohn massey 1258857352|%e %b %Y, %H:%M %Z|agohover

I have been working with the problems where one or the other variables that is JONL1 and JOHL5 meet the criterion 0=dim(
When done the prgmREDUE2 is called which is a completely separate program. There are two separate routines down this program with separate cases. When I run a controlled test where neither of the two cases of 0=dim( everything works fine. Since there is only variable to process I just used all the code previously given except for the first argument command. My response is that from the program is that the values of JOHL1, JONL5 and OVER are all the same. I have run a controlled program where JOHL5 should have no values. Please help me.

If 0=dim(⌊JONL5)
Then
⌊JONL1→⌊OVER
SortA(⌊OVER
augment({0},⌊OVER→⌊OVER
For(A,dim(ΔList(⌊OVER)),1,–1
ΔList(⌊OVER
If not(Ans(A
augment(seq(⌊OVER(I),I,1,A-1),seq(⌊OVER(I),I,A+1,dim(⌊OVER→⌊OVER
End
seq(⌊OVER(I),I,2,dim(⌊OVER→⌊OVER
prgmREDUE2
End
I have also tried:

If 0=dim(⌊JONL5)
Then
⌊JONL1→⌊OVER
prgmREDUE2
End

Same result it makes me wonder if my 0=dim( really represents a variable which has no content.

unfold Re: COMBINING TWO LISTS by john masseyjohn massey, 1258857352|%e %b %Y, %H:%M %Z|agohover
Re: COMBINING TWO LISTS
john masseyjohn massey 1258907485|%e %b %Y, %H:%M %Z|agohover

Perhaps my problem is not clear when you just see a single list. Below is the complete "summing of two lists" program. I added the an "and" statement to the "If" statement,

If 0=dim(⌊JONL1) and 0≠dim(⌊JONL5
Then
⌊JONL5→⌊OVER
SortA(⌊OVER
augment({0},⌊OVER→⌊OVER
For(A,dim(ΔList(⌊OVER)),1,–1
ΔList(⌊OVER
If not(Ans(A
augment(seq(⌊OVER(I),I,1,A-1),seq(⌊OVER(I),I,A+1,dim(⌊OVER→⌊OVER
End
seq(⌊OVER(I),I,2,dim(⌊OVER→⌊OVER
prgmREDUE2
End
If 0=dim(⌊JONL5) and 0≠dim(⌊JONL1
Then
⌊JONL1→⌊OVER
SortA(⌊OVER
augment({0},⌊OVER→⌊OVER
For(A,dim(ΔList(⌊OVER)),1,–1
ΔList(⌊OVER
If not(Ans(A
augment(seq(⌊OVER(I),I,1,A-1),seq(⌊OVER(I),I,A+1,dim(⌊OVER→⌊OVER
End
seq(⌊OVER(I),I,2,dim(⌊OVER→⌊OVER
prgmREDUE2
End
If 0=dim(⌊JONL1) and 0=dim(⌊JONL5
Output(1,1,"SMART AND FAST TOO
If 0≠dim(⌊JONL1) and 0≠dim(⌊JONL5
augment(⌊JONL1,⌊JONL5→⌊OVER
SortA(⌊OVER
augment({0},⌊OVER→⌊OVER
For(A,dim(ΔList(⌊OVER)),1,–1
ΔList(⌊OVER
If not(Ans(A
augment(seq(⌊OVER(I),I,1,A-1),seq(⌊OVER(I),I,A+1,dim(⌊OVER→⌊OVER
End
seq(⌊OVER(I),I,2,dim(⌊OVER→⌊OVER
prgmREDUE2
End

unfold Re: COMBINING TWO LISTS by john masseyjohn massey, 1258907485|%e %b %Y, %H:%M %Z|agohover
Re: COMBINING TWO LISTS
Timothy FosterTimothy Foster 1258925710|%e %b %Y, %H:%M %Z|agohover

What is exactly the problem? Is there an error or something not doing what it is supposed to do?

unfold Re: COMBINING TWO LISTS by Timothy FosterTimothy Foster, 1258925710|%e %b %Y, %H:%M %Z|agohover
Re: COMBINING TWO LISTS
john masseyjohn massey 1258946528|%e %b %Y, %H:%M %Z|agohover

You see the 0=dim(JONL1 statement then by definition the value reported by JONL1 should be "{ }" but it's value is the same as JONL5.

Please advise.

unfold Re: COMBINING TWO LISTS by john masseyjohn massey, 1258946528|%e %b %Y, %H:%M %Z|agohover
Re: COMBINING TWO LISTS
john masseyjohn massey 1258950265|%e %b %Y, %H:%M %Z|agohover

It is in the rest of the program. I will work on it tomarrow.

unfold Re: COMBINING TWO LISTS by john masseyjohn massey, 1258950265|%e %b %Y, %H:%M %Z|agohover
Re: COMBINING TWO LISTS
 brt93yoda brt93yoda 1258957145|%e %b %Y, %H:%M %Z|agohover

…were not going to deal with loosing the "1" in the list…

Not to be rude or anything, but its losing not loosing =p

unfold Re: COMBINING TWO LISTS by  brt93yoda brt93yoda, 1258957145|%e %b %Y, %H:%M %Z|agohover
Re: COMBINING TWO LISTS
Timothy FosterTimothy Foster 1258984417|%e %b %Y, %H:%M %Z|agohover

the value reported by JONL1 should be "{ }"

Well, if you recall an empty list, or null set, then a dimension error will occur.

I don't know why JONL1 and JONL5 are identical if JONL1 is supposed to be null since those lists don't seem to be changed in the code you provided. Something must be happening elsewhere for the lists to be improperly changed.

unfold Re: COMBINING TWO LISTS by Timothy FosterTimothy Foster, 1258984417|%e %b %Y, %H:%M %Z|agohover
Re: COMBINING TWO LISTS
john masseyjohn massey 1258992670|%e %b %Y, %H:%M %Z|agohover

I found the problem. It was not in this problem's posting. I will advise if I uncover other issues.

unfold Re: COMBINING TWO LISTS by john masseyjohn massey, 1258992670|%e %b %Y, %H:%M %Z|agohover
New post