I have the following problem. Here is an example of my problem.

I have a list called OVER1 that holds {1,0,3,0,5,0,7,0,0,0,0,0,0,0,0,0}
I want code to remove all the "0s"
This should result with OVER1 holding {1,3,5,7}
Then I will do this

For(J,1,Dim(OVER1
If JONL1(J)=0 and JONL5(J)=0

Here I need code to remove that "J" value from OVER1 if for example when JONL1(J)=0 and JONL5(J)=0 that "J" is 3
Then OVER1 will hold {1,5,7}
Here is the solution to the first part of your problem, and the answer to the second part would be done in the same way.


Code:

  :0→A
:0→dim(L2
:For(J,1,dim(L1
:¦ If 0≠L1(J
:¦ A+1→A
:End
:A→dim(L2
:0→A
:For(J,1,dim(L1
:¦ If 0≠L1(J
:¦ Then
:¦ ¦ A+1→A
:¦ ¦ Pause A
:¦ ¦ L1(J)→L2(A
:¦ End
:End

© Copyright 2000-2010 Cemetech & Kerm Martian :: Page Execution Time: 0.535102 seconds.
Thanks for your quick response. I am having a little problem with understanding your code. I my post I mentioned OVER1 as being my list.
If I understand your post then your L1 is my OVER1. Is that correct?

I have had significant problems integrating programs the use L1..L6.

I would like to rename L2 to ⌊L2. Do you see any conflict with that?

I have more questions but I will settle with that for now.
L1 is your OVER1 list, and yes you can rename the L2, I only used them because it was a lot quicker for me to use them.
@lafferjm: Storing to 1+dim(list automatically adjusts the list's length. So, you only need half your code.

If you find a J for which both LJONL1(J) and LJONL5(J) are zero, LOVER1*(LOVER1≠J should zero-out the element that equals J. You can then reapply lafferjm's upcoming code on that.
If the non-zero numbers are in increasing order (as they are for you John), you can just do this


Code:
:SortD(LOVER1
:sum((LOVER1!=0)-->dim(LOVER1
:SortA(LOVER1


again, "!=" means "not equal to"

In addition, here's a way to remove an element (#J) from a list (L1), though I recommend that you use the above code instead.


Code:
:augment({1},L1-->L1
:augment(L1,{1}-->L1
:augment(seq(L1(X),X,1,J),seq(L1(X),X,J+2,dim(L1))-->L1
:seq(L1(X),X,2,dim(L1)-1)-->L1


It's slow, but hey, it works.
Offtopic - lafferjm, thanks for retaining the SourceCoder copyright! Smile
KermMartian wrote:
Offtopic - lafferjm, thanks for retaining the SourceCoder copyright! Smile


Lol, no problem I remember you saying something to me before about not using it, so I remembered to this time.

@weregoose: I tried doing that and for some reason it always added a 0 inbetween the elements.
Well, all you wonderful helpers, here is my understand of what I have seen here today. I tried the code above the For statement and that worked exactly as advertised. All this is what I want to use. Are there any questions? If not a couple of posts that said "Go for it Man" would be nice.

SortD(⌊OVER1
sum((⌊OVER1≠0)→dim(⌊OVER1
SortA(⌊OVER1
For(J,1,dim(⌊OVER1
If ⌊JONL5(J)=0 and ⌊JONL1(J)=0
⌊OVER1*(⌊OVER1≠J
I have tested the the first three lines in the code I have previously posted. It works.

However the last three lines do not. I have added a small program that is not shown in my posting that allows me to look at OVER1 and "J". It shows that "3" which is where the test condition occurred is still in OVER1. Further it reports that J=1

Given that I know that the first three lines work, I see nothing wrong with the "For( J " statement.

I can only conclude there is something wrong with the last two lines in the code.
I do not know how to test the last lines separately.

Please advise.

Code:
For(J,1,dim(⌊OVER1
If ⌊JONL5(J)=0 and ⌊JONL1(J)=0
⌊OVER1*(⌊OVER1≠J


Could you explain what you want this code to do? Your code doesn't store anything Question
Let us say that I have {1,0,3,0,5,0,7,0,0,0,0,0,0,0,0,0}-->OVER1

The first three lines of code should remove all the "0s" in the code. So OVER1 now holds {1,3,5,7}. I have tested that. It works.

When running the first regression of REDUE22. At J=3 I satisfied the "If" statement. When I ran prgmSHOWSTUF at the end of the code OVER1 held {1,3,5,7} and J=1, when it should have held{1,5,7} I do not believe that J can have a value there. Thus I believe this line of code "⌊OVER1*(⌊OVER1≠J " is not working

When I get this code running I will add prgmREDUE22 to this code to start the second regression of REDUE22

Not clear. Fire away.
On the home screen, see what this does: {1,3,5,7→L1

Press enter to store, and then type L1=7.

(Is your calculator with you? You should be doing this in real-time in order to pick it up faster!)

Executing L1=7 compares every element in the list, and the result is a new list of true-or-false responses as represented by ones and zeros, respectively.

This expression "stretches out" when interpreted, becoming {1=7,3=7,5=7,7=7}, which resolves to {0,0,0,1}. Pretty clear-cut logic, isn't it?

L1≠7 asks the opposite, and the result is an outcome that is inverted from the one prior (i.e., ones will become zeros, and zeros will become ones).

If you've worked with truth tables, then all this should be pretty straightforward.

Now, if we take the second of these two lists and multiply it by {1,3,5,7} (our original list), then what does that evaluate as?

{1,3,5,7}*{1,1,1,0} = {1*1,3*1,5*1,7*0} = {1,3,5,0}

Note how the last element, having been equal to 7, now drops to a zero.

Another example is L1≠J (where J equals 3).

L1≠J returns {1,0,1,1}. This is because we have requested, for each element, whether or not it was unequal to J.

1, 5, and 7 were not equal to J, so the test was "true" for each of these cases. Thus, a "1" fills their positions in a new list.

The 3 in that list, however, was equal to J, so the inferred 3≠J came out as "false". Thus, a zero goes there instead.

When we multiply this answer by L1, we get the following:

L1*(L1≠J) = {1,3,5,7}*{1,0,1,1} = {1,0,5,7}

Note that this process does not update L1. We'd have to store the new list ourselves:

L1*(L1≠J)→L1
Good to hear from you weregoose,
All that said, the last line in the code should read

⌊OVER1*(⌊OVER1≠J)→⌊OVER1
Not
⌊OVER1*(⌊OVER1≠J)

Right?
Very Happy
I tested. No workie Confused
I figured out a way to test the code.

Here it is

{1,0,3,0,5,0,7,0,0,0,0,0,0,0,0,0}→⌊OVER1
SortD(⌊OVER1
sum((⌊OVER1≠0)→dim(⌊OVER1
SortA(⌊OVER1
prgmSHOWSTUF // OVER1 holds {1,3,5,7} which it should.
For(J,1,dim(⌊OVER1
If J=3 //you can see that I have replaced the If statement with this.
⌊OVER1*(⌊OVER1≠J)→⌊OVER1
prgmSHOWSTUF // OVER1 holds {1,3,5,7} which it should not. It should be {1,5,7}

Since this is such a simple test program you all can test your solutions.

I pray that you will find one. Very Happy
Does it hold {1,3,5,7} on the third pass? J only equals 3 then.


Code:
PROGRAM:BENCH
{1,3,5,7→L1
For(J,1,dim(L1
If J=3
L1*(L1≠J)→L1
Pause L1
End
Some additional information.

This is SHOWSTUF

ClrHome
Output(1,1,"L4 "
Output(1,5,⌊JONL4
Output(2,1,"L5 "
Output(2,5,⌊JONL5
Output(3,1,"L1 "
Output(3,5,⌊JONL1
Output(4,1,"OV "
Output(4,5,⌊OVER1
Output(8,1,"JA "
Output(8,5,J
Pause
ClrHome

I am not sure I understand you question. We are skipping those flash cards / problems where there are "0s" in OVER1. So on the second pass
J=3. That is the J we value I want to remove from OVER1.

more question? fire away.
After it has been turned into a zero, you can use the routine mentioned earlier to strip out that zero. Smile
After the program runs OVER1 holds {1,3,5,7} which is the same content it held after the "0s" were removed by the first lines of the code.

It should have removed the 3 from the list because of the replacement of the If statement with If J=3 Which should have resulted in {1,5,7}

In the second regression of REDUE22 there is code to put the "0s" back in OVER1. !n this case OVER1 should look like this:

{1,0,0,5,0,7,0,0,0,0,0,0,0,0,0,0}

Notice that there is a "0" in place of the "3" which should have been removed if the code was working

More questions? Fire when ready Gridley
  
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 2
» 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