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
Recent Threads
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
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
why not
augment(L₁, L₂) →L₃
Visit Calccrypto for info on crypto
As bxsciencer mentioned, augment( will combine any two lists into one lists.
— Blog ~ Life's Handbook
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.
Well I will try the augment in the program. I the meantime, how do you suggest that we deal with duplicates and ascending order?
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
I never knew the SortA( and Augment commands
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
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.
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
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
Either solution will work.
thanks for your quick responses from the master programmers!
The master tester is off to test.
john
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
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
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
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
— Blog ~ Life's Handbook
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
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
— Blog ~ Life's Handbook
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
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
— Blog ~ Life's Handbook
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
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.
— Blog ~ Life's Handbook
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.
Oh, sorry, I had a typo…
Change:
augment({0},∟JONL3
augment({0},∟JONL3→∟JONL3
That's why the 1 is disappearing because the 0 wasn't picked up…
— Blog ~ Life's Handbook
Hi Timothy,
The change worked wonderfully!
Thank you very much. I continue to learn from you!
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
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?
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
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
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.
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
What is exactly the problem? Is there an error or something not doing what it is supposed to do?
— Blog ~ Life's Handbook
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.
It is in the rest of the program. I will work on it tomarrow.
…were not going to deal with loosing the "1" in the list…
Not to be rude or anything, but its losing not loosing =p
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.
— Blog ~ Life's Handbook
I found the problem. It was not in this problem's posting. I will advise if I uncover other issues.