![]() |
if your printing inside a if to get these switch it to if(,,) form and switch which of the last 2 it's in.
|
[QUOTE=science_man_88]if your printing inside a if to get these switch it to if(,,) form and switch which of the last 2 it's in.
[/QUOTE] Can you give some smaple code to elaborate what you posted? It will clear things up. |
[CODE]if(x%6==1 || x%6==5 ,print(x))[/CODE]
is like the usual way for most I think. [CODE]if(x%6==1 || x%6==5 ,print(x),)[/CODE] is another way to put this in the longer notation if i want the opposite i just change the position to the other and i get. [CODE]if(x%6==1 || x%6==5 ,,print(x))[/CODE] now it will print every number not in 6x+1 or 6x+5 so just that change in position is saying the same as: [CODE]if(x%6!=1 && x%6!=5 ,print(x))[/CODE] but it makes it easier as you don't have to add anything except a comma to an existing code rather than changing 4 characters in this case. |
[CODE](12:10) gp > for(x=1,20,if(x%6==1 || x%6==5,print(x)))
1 5 7 11 13 17 19 (12:10) gp > for(x=1,20,if(x%6==1 || x%6==5,,print(x))) 2 3 4 6 8 9 10 12 14 15 16 18 20 (12:10) gp >[/CODE] see the difference ? |
Yes, but you shouldn't be printing at all. Instead of writing print(x) you should be writing something like v[x] = 0.
|
I was just giving example code for him to look over.
|
[QUOTE=CRGreathouse]Yes, but you shouldn't be printing at all. Instead of writing print(x) you should be writing something like v[x] = 0.
[/QUOTE] It would only give the good old "Not a vector" error. |
not if you make a vector and try to edit it on the fly like I sent in a pm to CRG the hard part for me was not filling it with 0's as he wanted me to.
can't remeber what i did to make it act dynamic but I can try to figure it out. |
[CODE]v=vector(1,n,0);for(x=1,10,if(isprime(x),v=concat(v,x)));for(i=1,(#v)-1,v[i]=v[i+1])[/CODE]
there's one thing I still can't do and that's take off the end that repeats so no number repeats. doh vecextract can work lol I just extract the last one. didn't work. |
made a code that works by replacing the 0 with 2 and starting at 3 and searching then I didn't need the index shift code.
|
[QUOTE=3.14159;226677]It would only give the good old "Not a vector" error.[/QUOTE]
Doesn't that message tell you what to do? It says, "v isn't a vector, so I can't treat it like a vector". So... drumroll... you need to make a vector v. This is done with the vector command, unsurprisingly: [code]v=vector(1000)[/code] But I've already written this a goodly number of times on this thread. Actually, I think I'll make this one my last; in the future I'll just refer to this post number. |
| All times are UTC. The time now is 23:09. |
Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2021, Jelsoft Enterprises Ltd.