![]() |
|
|
#2080 |
|
Jun 2003
5,087 Posts |
Code:
c=vector(10, n, n)
vecextract(c, concat("1..", #c-1))
vecextract(c, concat("2..", #c))
|
|
|
|
|
|
#2081 |
|
"Forget I exist"
Jul 2009
Dumbassville
26×131 Posts |
Code:
c=concat(c,c[1]);c=vector(#c-1,n,c[n+1]) Last fiddled with by science_man_88 on 2010-12-15 at 16:52 |
|
|
|
|
|
#2082 |
|
"Forget I exist"
Jul 2009
Dumbassville
100000110000002 Posts |
|
|
|
|
|
|
#2083 |
|
May 2010
Prime hunting commission.
24×3×5×7 Posts |
Meh. I don't quite know the code to make a custom vector that returns something other than 1 and 0, other than insert code into the vector command.
|
|
|
|
|
|
#2084 | |
|
"Forget I exist"
Jul 2009
Dumbassville
26·131 Posts |
Quote:
Code:
x=vector(100,n,n) ; makes x have 100 indexes with each indexes value equals to the index. Code:
x=vector(100,n,if(isprime(n,n))) ; makes a vector of 100 indexes with the index value equal to the index if the index value is prime. otherwise the index value is 0. |
|
|
|
|
|
|
#2085 | |
|
Aug 2006
3·1,993 Posts |
Quote:
Certainly vectors aren't appropriate for all tasks, but it's good to use them when they are. ---- Here's a trick* I just learned. When you want to build a vector element-by-element, a better way than v = concat(v, new_element) is to make a list, store elements with listput, then convert (if needed) to a vector with Vec. So Code:
natural(N)={
my(l=List());
for(n=1,N,listput(l,n));
Vec(l)
};
Code:
natural1(N)={
my(v=[]);
for(n=1,N,v=concat(v,n));
v
};
* Not "something clever" but "the way I always should have been doing it". Last fiddled with by CRGreathouse on 2010-12-16 at 05:13 Reason: fixed dumb mistake; thanks, axn |
|
|
|
|
|
|
#2086 |
|
Jun 2003
5,087 Posts |
|
|
|
|
|
|
#2087 |
|
Aug 2006
597910 Posts |
Hah! Fixed it.
|
|
|
|
|
|
#2088 |
|
"Forget I exist"
Jul 2009
Dumbassville
26×131 Posts |
Code:
(09:42)>natural(100000)
%3 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12,
1851, 1852, 1853, 1854, 1855, 1856, 1857, 185
7, 3518, 3519, 3520, 3521, 3522, 3523, 3524,
5184, 5185, 5186, 5187, 5188, 5189, 5190, 519
0, 6851, 6852, 6853, 6854, 6855, 6856, 6857,
8517, 8518, 8519, 8520, 8521, 8522, 8523, 852
157, 10158, 10159, 10160, 10161, 10162, 10163
, 11586, 11587, 11588, 11589, 11590, 11591, 1
3014, 13015, 13016, 13017, 13018, 13019, 1302
2, 14443, 14444, 14445, 14446, 14447, 14448,
15871, 15872, 15873, 15874, 15875, 15876, 158
99, 17300, 17301, 17302, 17303, 17304, 17305,
18728, 18729, 18730, 18731, 18732, 18733, 18
156, 20157, 20158, 20159, 20160, 20161, 20162
, 21585, 21586, 21587, 21588, 21589, 21590, 2
3013, 23014, 23015, 23016, 23017, 23018, 2301
1, 24442, 24443, 24444, 24445, 24446, 24447,
25870, 25871, 25872, 25873, 25874, 25875, 258
98, 27299, 27300, 27301, 27302, 27303, 27304,
28727, 28728, 28729, 28730, 28731, 28732, 28
155, 30156, 30157, 30158, 30159, 30160, 30161
, 31584, 31585, 31586, 31587, 31588, 31589, 3
3012, 33013, 33014, 33015, 33016, 33017, 3301
0, 34441, 34442, 34443, 34444, 34445, 34446,
35869, 35870, 35871, 35872, 35873, 35874, 358
97, 37298, 37299, 37300, 37301, 37302, 37303,
38726, 38727, 38728, 38729, 38730, 38731, 38
154, 40155, 40156, 40157, 40158, 40159, 40160
, 41583, 41584, 41585, 41586, 41587, 41588, 4
3011, 43012, 43013, 43014, 43015, 43016, 4301
9, 44440, 44441, 44442, 44443, 44444, 44445,
45868, 45869, 45870, 45871, 45872, 45873, 458
96, 47297, 47298, 47299, 47300, 47301, 47302,
48725, 48726, 48727, 48728, 48729, 48730, 48
153, 50154, 50155, 50156, 50157, 50158, 50159
, 51582, 51583, 51584, 51585, 51586, 51587, 5
3010, 53011, 53012, 53013, 53014, 53015, 5301
8, 54439, 54440, 54441, 54442, 54443, 54444,
55867, 55868, 55869, 55870, 55871, 55872, 558
95, 57296, 57297, 57298, 57299, 57300, 57301,
58724, 58725, 58726, 58727, 58728, 58729, 58
152, 60153, 60154, 60155, 60156, 60157, 60158
, 61581, 61582, 61583, 61584, 61585, 61586, 6
3009, 63010, 63011, 63012, 63013, 63014, 6301
7, 64438, 64439, 64440, 64441, 64442, 64443,
65866, 65867, 65868, 65869, 65870, 65871, 658
94, 67295, 67296, 67297, 67298, 67299, 67300,
68723, 68724, 68725, 68726, 68727, 68728, 68
151, 70152, 70153, 70154, 70155, 70156, 70157
, 71580, 71581, 71582, 71583, 71584, 71585, 7
3008, 73009, 73010, 73011, 73012, 73013, 7301
6, 74437, 74438, 74439, 74440, 74441, 74442,
75865, 75866, 75867, 75868, 75869, 75870, 758
93, 77294, 77295, 77296, 77297, 77298, 77299,
78722, 78723, 78724, 78725, 78726, 78727, 78
150, 80151, 80152, 80153, 80154, 80155, 80156
, 81579, 81580, 81581, 81582, 81583, 81584, 8
3007, 83008, 83009, 83010, 83011, 83012, 8301
5, 84436, 84437, 84438, 84439, 84440, 84441,
85864, 85865, 85866, 85867, 85868, 85869, 858
92, 87293, 87294, 87295, 87296, 87297, 87298,
88721, 88722, 88723, 88724, 88725, 88726, 88
149, 90150, 90151, 90152, 90153, 90154, 90155
, 91578, 91579, 91580, 91581, 91582, 91583, 9
3006, 93007, 93008, 93009, 93010, 93011, 9301
4, 94435, 94436, 94437, 94438, 94439, 94440,
95863, 95864, 95865, 95866, 95867, 95868, 958
91, 97292, 97293, 97294, 97295, 97296, 97297,
98720, 98721, 98722, 98723, 98724, 98725, 98
(09:42)>##
*** last result computed in 125 ms.
(09:42)>natural1(N)={
my(v=[]);
for(n=1,N,v=concat(v,n));
v
};
(09:42)>natural1(100000)
*** user interrupt after 3mn, 39,875 ms.
Last fiddled with by science_man_88 on 2010-12-16 at 13:51 |
|
|
|
|
|
#2089 |
|
"Forget I exist"
Jul 2009
Dumbassville
26×131 Posts |
those test are with minimal memory with my maximum I was able to do natural(10000000) in under 17 seconds according to the timing it gave. I wonder how much isprime would slow something like this down lol. looks like me adding a isprime check and trying up to 10000000 actually sped it up, listed all primes under 10 million in under 10 seconds according to the timer.That's without turning it into a forstep loop to only check 6n+1 of 6n-1.
Last fiddled with by science_man_88 on 2010-12-16 at 14:19 |
|
|
|
|
|
#2090 |
|
Aug 2006
3×1,993 Posts |
Yes -- natural1 would take a long, long time to do that. It took 4:59.8 to do 10^5; based on curve-fitting with smaller numbers I estimate it would take about a month for it to do 10^7.
|
|
|
|
![]() |
| Thread Tools | |
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 |