mersenneforum.org  

Go Back   mersenneforum.org > Math Stuff > Computer Science & Computational Number Theory > PARI/GP

Reply
 
Thread Tools
Old 2010-08-23, 14:53   #760
science_man_88
 
science_man_88's Avatar
 
"Forget I exist"
Jul 2009
Dumbassville

20C016 Posts
Default

if your printing inside a if to get these switch it to if(,,) form and switch which of the last 2 it's in.
science_man_88 is offline   Reply With Quote
Old 2010-08-23, 14:59   #761
3.14159
 
3.14159's Avatar
 
May 2010
Prime hunting commission.

24×3×5×7 Posts
Default

Quote:
Originally Posted by 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.
Can you give some smaple code to elaborate what you posted? It will clear things up.

Last fiddled with by 3.14159 on 2010-08-23 at 14:59
3.14159 is offline   Reply With Quote
Old 2010-08-23, 15:07   #762
science_man_88
 
science_man_88's Avatar
 
"Forget I exist"
Jul 2009
Dumbassville

26×131 Posts
Default

Code:
if(x%6==1 || x%6==5 ,print(x))
is like the usual way for most I think.

Code:
if(x%6==1 || x%6==5 ,print(x),)
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))
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))
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.
science_man_88 is offline   Reply With Quote
Old 2010-08-23, 15:11   #763
science_man_88
 
science_man_88's Avatar
 
"Forget I exist"
Jul 2009
Dumbassville

838410 Posts
Default

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 >
see the difference ?
science_man_88 is offline   Reply With Quote
Old 2010-08-23, 15:14   #764
CRGreathouse
 
CRGreathouse's Avatar
 
Aug 2006

10111010110112 Posts
Default

Yes, but you shouldn't be printing at all. Instead of writing print(x) you should be writing something like v[x] = 0.
CRGreathouse is offline   Reply With Quote
Old 2010-08-23, 15:15   #765
science_man_88
 
science_man_88's Avatar
 
"Forget I exist"
Jul 2009
Dumbassville

26×131 Posts
Default

I was just giving example code for him to look over.
science_man_88 is offline   Reply With Quote
Old 2010-08-23, 15:22   #766
3.14159
 
3.14159's Avatar
 
May 2010
Prime hunting commission.

24·3·5·7 Posts
Default

Quote:
Originally Posted by CRGreathouse
Yes, but you shouldn't be printing at all. Instead of writing print(x) you should be writing something like v[x] = 0.
It would only give the good old "Not a vector" error.
3.14159 is offline   Reply With Quote
Old 2010-08-23, 15:24   #767
science_man_88
 
science_man_88's Avatar
 
"Forget I exist"
Jul 2009
Dumbassville

203008 Posts
Default

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.

Last fiddled with by science_man_88 on 2010-08-23 at 15:26
science_man_88 is offline   Reply With Quote
Old 2010-08-23, 15:33   #768
science_man_88
 
science_man_88's Avatar
 
"Forget I exist"
Jul 2009
Dumbassville

26×131 Posts
Default

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])
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.

Last fiddled with by science_man_88 on 2010-08-23 at 15:39
science_man_88 is offline   Reply With Quote
Old 2010-08-23, 15:43   #769
science_man_88
 
science_man_88's Avatar
 
"Forget I exist"
Jul 2009
Dumbassville

26×131 Posts
Default

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.

Last fiddled with by science_man_88 on 2010-08-23 at 15:52
science_man_88 is offline   Reply With Quote
Old 2010-08-23, 17:55   #770
CRGreathouse
 
CRGreathouse's Avatar
 
Aug 2006

597910 Posts
Default

Quote:
Originally Posted by 3.14159 View Post
It would only give the good old "Not a vector" error.
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)
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.
CRGreathouse is offline   Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Why do I sometimes see all the <> formatting commands when I quote or edit? cheesehead Forum Feedback 3 2013-05-25 12:56
Passing commands to PARI on Windows James Heinrich Software 2 2012-05-13 19:19
Ubiquity commands Mini-Geek Aliquot Sequences 1 2009-09-22 19:33
64-bit Pari? CRGreathouse Software 2 2009-03-13 04:22
Are these commands correct? jasong Linux 2 2007-10-18 23:40

All times are UTC. The time now is 23:07.


Fri Aug 6 23:07:25 UTC 2021 up 14 days, 17:36, 1 user, load averages: 3.82, 3.85, 3.90

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2021, Jelsoft Enterprises Ltd.

This forum has received and complied with 0 (zero) government requests for information.

Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any later version published by the Free Software Foundation.
A copy of the license is included in the FAQ.