![]() |
[QUOTE=CRGreathouse]Let's see. (b) evaluates to b, v[b] evaluates to the b-th value in v. If v happens to be a vector, and #v is at least as large as the value of b, then it passes whatever happens to be in that location in the vector to forstep. Forstep ignores the values its given (unlike, say, sum() or prod()), so this code has the following behavior:
* If v is a vector with size at least as large as the final value of b (around 10^a), then do nothing. * If lift(Mod(-1,x)/n) is greater than 10^a, then do nothing. * Otherwise, if v is a vector, throw an "index out of bounds" error. * If v is not a vector, and lift(Mod(-1,x)/n) is <= 10^a, then throw a "_[_]: not a vector" error.[/QUOTE] Great. What if I pinned a return value on it instead? Oh. Right. Returns the first value |
CRG I got my code to work to find primes and fill a vector of 0's with them I'm thinking of how to make a function VecApp(v,x,f) that takes one vector(v) into another vector(f) with 1 extra element which is appended with value x maybe that will make it easier on me. I think this would need to say something like f[i] = v[i] f[i]+1 = x but I'm without reading them all I have no idea how to get i not to go over the amount of indexes of v.
|
[QUOTE=3.14159;226190]Great. What if I pinned a return value on it instead? Oh. Right. Returns the first value[/QUOTE]
Just look at my code for how to use the vector! |
scratch f we can just use v=f to redefine it back to v after.
|
[QUOTE=science_man_88;226201]CRG I got my code to work to find primes and fill a vector of 0's with them I'm thinking of how to make a function VecApp(v,x,f) that takes one vector(v) into another vector(f) with 1 extra element which is appended with value x maybe that will make it easier on me. I think this would need to say something like f[i] = v[i] f[i]+1 = x but I'm without reading them all I have no idea how to get i not to go over the amount of indexes of v.[/QUOTE]
[code]concat([1,2,3],10)[/code] |
I'm an idiot thanks.
|
[QUOTE=CRGreathouse]Just look at my code for how to use the vector!
[/QUOTE] my(v=vectorsmall(sz, i, 1))? What is supposed to be the substitution here? |
[QUOTE=science_man_88;226205]I'm an idiot thanks.[/QUOTE]
You were trying to write a function that already existed. That's pretty common. I wrote my own version of eint1, at the very least -- but probably others, too. |
A 1 in 10[sup]65[/sup] chance:
I entered a(65), which is nextprime(random(10^65)). The result: 2. |
Well, 3 in 10^65 anyway. Wow.
|
[QUOTE=CRGreathouse]Well, 3 in 10^65 anyway. Wow.
[/QUOTE] It was in fact, too good to be true. It turned out PARI was messed for a while. I entered a(7) and got 2, 6 times in a row. I tried a(8) through a(12), and got 2, about 20 times on end. This would normally happen only about 1 in ≈10[sup]163[/sup] times. I'm going with PARI being a bit buggy. Or did I have a supreme stroke of luck and just defy odds of 1 in 10[sup]163[/sup]? Also: The lottery should be changed to guessing 10 random numbers between 1 and 10[sup]15[/sup]. (To ensure that nobody wins, :devil:) |
You may have inadvertently overwritten a. Try ?a to see the current definition.
|
[QUOTE=CRGreathouse]You may have inadvertently overwritten a. Try ?a to see the current definition.
[/QUOTE] Nope. I changed nothing. It was either incredible luck or the computer fucking up. |
[CODE](15:27) gp > v=vector(1,n,0);a=1;for(x=1,10000,if(isprime(x),v[a]=x;concat(v[],0);a=a+1))
[COLOR="Red"]*** unused characters: v=vector(1,n,0);a=1;for(x=1,10000,if(is ^--------------------[/COLOR][/CODE] |
I'm leaning towards the latter being true.
@sm88: Too many arguments, failed to specify whether or not a=1 was part of the command, a=1 treated as its own command |
[QUOTE=3.14159;226216]I'm leaning towards the latter being true.
@sm88: Too many arguments, failed to specify whether or not a=1 was part of the command, a=1 treated as its own command[/QUOTE] it should be it's own command. it's only when i used concat() that this happened. |
[QUOTE=3.14159;226214]Nope. I changed nothing. It was either incredible luck or the computer fucking up.[/QUOTE]
I'm leaning toward "you used a as a variable in a function without using local or my" which would explain it pretty well. |
[QUOTE=3.14159;226216]@sm88: Too many arguments, failed to specify whether or not a=1 was part of the command, a=1 treated as its own command[/QUOTE]
[QUOTE=science_man_88;226217]it should be it's own command. it's only when i used concat() that this happened.[/QUOTE] I don't know what either of these mean. |
[QUOTE=CRGreathouse]I'm leaning toward "you used a as a variable in a function without using local or my" which would explain it pretty well.
[/QUOTE] Nope. I defined f(x, n) as follows: Print nextprime(x), followed by * , followed by nextprime(n), followed by printing the product of those two. In other words, a semiprime generator that gives the factors used to produce the semiprime as well. a(n) = nextprime(random(10^n)). a and f were well-defined. a was never a variable, it is a function. a simply gives an n-digit prime most of the time. Therefore, there was no error in my defined functions. |
[CODE] v=vector(1250,n,0);a=1;for(x=1,10000,if(isprime(x),v[a]=x;a=a+1))[/CODE]
works but you already have to know the # of primes under the x upper bound to not get an error or a 0 at the end. what I want to do is add a 0 into v every time a prime is found so as to have no 0's at the end of it all and to only have the number of indices necessary to list all the primes under a given number once the vector is made I can get a sieve like the sieve of Eratosthenes to try and work with it to create a bigger list instead of asking isprime hopefully I can make a way to check primality quicker and then make a function that uses the vector indices to check Prime2(x). |
[QUOTE=CRGreathouse]I don't know what either of these mean.
[/QUOTE] I was merely trying to explain sm88's error. |
[code]v=vector(1,n,0);
a=1; for(x=1,10000, if(isprime(x), v[a]=x; concat(v[],0); a=a+1 ) )[/code] I'm not sure what "concat(v[],0);" is trying to do, but it's not right. v[] will cause an error. If you replace v[] with something that isn't an error, like v, then the result would take v and concatenate it with 0, then throw the result away. Maybe you mean [code]v=concat(v,0);[/code] which would take v, append 0 to the end, and replace the old v with the "old v followed by a 0" vector. Here's how I would do what I think you're trying to do: [code]v=[]; for(x=1,10000, if(isprime(x), v=concat(v,x) ) )[/code] or even [code]v=[]; forprime(p=2,10000, v=concat(v,p) )[/code] or even [code]v=vector(primepi(10000)); i=0; forprime(p=2,10000, i++; v[i]=p )[/code] which I would usually write in the confusing programmer-ese as [code]v=vector(primepi(10000)); i=0; forprime(p=2,10000, v[i++]=p )[/code] |
[QUOTE=3.14159;226220]Nope. I defined f(x, n) as follows:
Print nextprime(x), followed by * , followed by nextprime(n), followed by printing the product of those two. In other words, a semiprime generator that gives the factors used to produce the semiprime as well. a(n) = nextprime(random(10^n)). a and f were well-defined. a was never a variable, it is a function. a simply gives an n-digit prime most of the time. Therefore, there was no error in my defined functions.[/QUOTE] Did you put in ?a ? What did it say? |
now if I only I could be smart like you so I could build you that helpful program lol.
|
[QUOTE=CRGreathouse]Did you put in ?a ? What did it say?
[/QUOTE] ?a = a(n) = nextprime(10^n)) |
[QUOTE=science_man_88;226226]now if I only I could be smart like you so I could build you that helpful program lol.[/QUOTE]
[i]I'm[/i] not smart enough to write that program, but maybe you are. You have a long way to go, though! Here are some possibly-relevant papers in case you decide to think more about this: [url=http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.132.8640&rep=rep1&type=pdf]mArachna – Ontology Engineering for Mathematical Natural Language Texts[/url] [url=http://mathweb.org/projects/mws/pubs/mkm08.pdf]MathWebSearch 0.4: A Semantic Search Engine for Mathematics[/url] etc. |
[QUOTE=3.14159;226232]?a = a(n) = nextprime(10^n))[/QUOTE]
I'm sure it didn't say that -- it's not in the form of a valid closure. But if it said [code]a(n) = nextprime(10^n)[/code] then it would never return 2 for n >= 1 -- it's a constant, no randomness. |
Now: Can we get back to the substitutions required to make the sieve for the k * n + 1?
|
[QUOTE=3.14159;226235]Now: Can we get back to the substitutions required to make the sieve for the k * n + 1?[/QUOTE]
Why don't you just download srsieve and use that? It'll be faster. |
[QUOTE=CRGreathouse]Why don't you just download srsieve and use that? It'll be faster.[/QUOTE]
Because it can only sieve for Proth numbers. |
[QUOTE=3.14159;226242]Because it can only sieve for Proth numbers.[/QUOTE]
It does more than Proth numbers. What, precisely, are you sieving for? Can you specify exactly for me? |
[QUOTE=CRGreathouse]It does more than Proth numbers. What, precisely, are you sieving for? Can you specify exactly for me?
[/QUOTE] k * n! + 1. |
Maybe this?
[url]http://fatphil.org/maths/factorial/[/url] Possibly even this? [url]http://pgllr.mine.nu/software/fsieve/[/url] |
[QUOTE=CRGreathouse]Maybe this?
[url]http://fatphil.org/maths/factorial/[/url] Possibly even this? [url]http://pgllr.mine.nu/software/fsieve/[/url][/QUOTE] The first is source code, luckily I downloaded some freeware to deal with C source code. |
[QUOTE=3.14159]The first is source code, luckily I downloaded some freeware to deal with C source code.[/QUOTE]
Nevermind that. I'm going to go to Generalized proths, using factorial and or primorial powers, just need a larger base range. Anything for that? |
[QUOTE=3.14159;226258]Nevermind that. I'm going to go to Generalized proths, using factorial and or primorial powers, just need a larger base range. Anything for that?[/QUOTE]
I can never keep track of all the names (especially since some are contradictory... e.g. several definitions for generalized Fermats). What form are these? |
can you make vectors of vectored strings ? if so we can do a find and replace like operation such that Pari can code it.
|
[QUOTE=3.14159]Nevermind that. I'm going to go to Generalized proths, using factorial and or primorial powers, just need a larger base range. Anything for that?
[/QUOTE] To continue endlessly quoting myself... PFGW's factor switch helps out for larger b. [QUOTE=3.14159]I can never keep track of all the names (especially since some are contradictory... e.g. several definitions for generalized Fermats). What form are these? [/QUOTE] Generalized proths = k * b[sup]n[/sup] + 1 where b is any integer ≥ 2. And: Please, show where I was self-contradictory. |
got the vector within vector worked out now I just need to check them out lol.
got it working with one catch need to quotes around the phrase in the input lol. but then unless we insert them and check it will be hard. oh and if you accidentally insert anything that gets typed over it wrecks it it seems. |
[CODE]try = [Vec(x="string"),Vec(x="suck"),Vec(x="primes")][/CODE]
and [CODE]x=3;y=Vec(input());if(y==try[x],print("really"))[/CODE] try it out if you want remember quotes and hopefully no messing up to make it work. |
[QUOTE=3.14159;226265]Generalized proths = k * b[sup]n[/sup] + 1 where b is any integer ≥ 2.[/QUOTE]
You can use srsieve for those. [QUOTE=3.14159;226265]And: Please, show where I was self-contradictory.[/QUOTE] I made no such accusation. |
[QUOTE=science_man_88;226281][CODE]try = [Vec(x="string"),Vec(x="suck"),Vec(x="primes")][/CODE][/QUOTE]
You probably want [CODE]try = [Vec("string"),Vec("suck"),Vec("primes")][/CODE] |
[QUOTE=CRGreathouse;226294]You probably want
[CODE]try = [Vec("string"),Vec("suck"),Vec("primes")][/CODE][/QUOTE] no it gave me a too few arguments error that way got it working never mind still needed the quotes. |
how do i check word/phrase by word/phrase through text if i need parentheses everywhere. get that under control then we can at least make a limited version.
basically we need a find and replace script to edit the text to something we can make Pari understand. |
we need to build a gp2c like exe that is more of a nl2gp (natural language to pari) compiler.
|
[CODE]y=Vec(input());for(x=1,3,forstep(i=1,#y,#try[x],if(y[i]==try[x][1],print("really"))))[/CODE]
what I've got working. had to make to: [CODE]y=Vec(input());for(x=1,3,for(i=1,#y,if(y[i]==try[x][1],print("really"))))[/CODE] |
[QUOTE=CRGreathouse]You can use srsieve for those.
[/QUOTE] Or NewPGen. [QUOTE=CRGreathouse]I made no such accusation. [/QUOTE] You said I made several contradictory names for various prime forms, and you were therefore accusing me of being internally inconsistent. Please show where I am internally inconsistent. |
[QUOTE=3.14159;226307]You said I made several contradictory names for various prime forms, and you were therefore accusing me of being internally inconsistent. Please show where I am internally inconsistent.[/QUOTE]
So read again: [QUOTE=CRGreathouse;226263]I can never keep track of all the names (especially since some are contradictory... e.g. several definitions for generalized Fermats). What form are these?[/QUOTE] He never accused [b]you[/b]! It was meant generally! |
Alright: My sieve only requires three arguments, as it is just Generalized proths. (Two for the kmin/kmax, one for the base and exponent)
Now it should be far easier to make all the appropriate substitutions and so on. @CRG/sm88: Any hints on the appropriate substitutions, as the amount of arguments are the same? Here is the [B]original[/B] code: [code]sieve(lim, sz, sm=1)={ my(v=vectorsmall(sz,i,1)); forprime(p=3,p2, b=znorder(Mod(2,p)); trap(,next, a=znlog(2293,Mod(2,p)) ); if(Mod(2,p)^a!=2293, print("bad at "p);next); a+=b*ceil((sm-a)/b); forstep(n=a,sz,b, v[n]=0 ) ); a=0; for(i=sm,sz,if(v[i],a++;write("abc.txt", i))); a };[/code] |
Make as many substitutions and modifications as you'd like. I'll try to make the appropriate substitutions/modifications to see if I can reach a finished product.
|
I thought of substituting the variables with the variables I designated, but this essentially does the same, and prints out the same factors, except it does so up to 10[sup]6[/sup].
Now it seems that substitutions didn't cut it. Any recommended modifications, anyone? |
one thing i find is you have a variable p2 declared as a maximum but no definition of it before hand that I know of.
|
[QUOTE=science_man_88]one thing i find is you have a variable p2 declared as a maximum but no definition of it before hand that I know of.
[/QUOTE] Damn. I forgot to change that to "lim". |
since you use znlog() you can just check if a is a factorial because g^n=x n gets stored in a so if a=c! then the exponent to check is c! not a! so checking if a is a factorial means if true a!=c!! or a double factorial if such a thing exist anyway I'll shut up.
|
you write i but unless you have a seperator you won't be able to figure out what's what in abc.txt I know I couldn't so adding "," to that call might be warranted if you want it to be understood.
|
[CODE]a=0;y=Vec(input());for(x=1,3,for(i=1,#y,for(p=2,#try[x]-1,if(y[i+(p-1)]==try[x][p],a=a+1;print("really")));if(a==#try[x]-2)))[/CODE]
is my newest attempt at what I wanted to help CRG with. unfortunately this gives me errors. |
can setsearch be used on strings if it could we can use that as find and possibly replace if we can find a way to make sure the replacement can fit into it.
got it without errors but not working. |
I have other ideas about how to but I don't know enough on the routines.
I was also thinking vecextract. |
[QUOTE=science_man_88;226401]can setsearch be used on strings[/QUOTE]
setsearch works on sets and also on ordered vectors, but not on arbitrary vectors or strings. I suggest you start by writing a "stringsearch(string_to_search, string_to_find)" function. |
[QUOTE=CRGreathouse]setsearch works on sets and also on ordered vectors, but not on arbitrary vectors or strings.
I suggest you start by writing a "stringsearch(string_to_search, string_to_find)" function[/QUOTE] Reduced the amount of arguments to three. I think it will be easier to make the appropriate substitutions and modifications now. |
[QUOTE=CRGreathouse;226404]setsearch works on sets and also on ordered vectors, but not on arbitrary vectors or strings.
I suggest you start by writing a "stringsearch(string_to_search, string_to_find)" function.[/QUOTE] yeah I found lex so [CODE]y=Vec(input());if(lex(y,"yes"),print("no"))[/CODE] now all we need is to check indexes against a vector of strings I think. |
oh one thing I forgot is maybe using vecextract to another vector may help comparison. as if the input is longer than the text to check against then it can never be equal so maybe extraction of the first #try[x] characters to a new vector and if we want to reuse the input we can concat() /// to the end or something then place that other vector concat() on the end then take the next until we hit out end symbol. then check the next string to check for.
|
[CODE]y=Vec(input());t=vecextract(y,"1..10");return(t)[/CODE]
my best attempt with vecextract i can't figure out the variables use I get a incorrect range error. |
well i got it working for 1 but I get a vector of numbers back not a string. got it working for a character but I needed quotes around the whole thing which is better than quotes around every phrase I guess. now I think i figured it out lol. well i can search for it now to replace it I'll put the find code together soon.
|
[CODE][COLOR="Yellow"](17:49) gp > [COLOR="White"]y=Vec(input());for(i=1,#try,c=vecextract(y,[1,2,3,4,5,6]);if(lex(c,try[i]),print(c)))
"string""suck""primes" ["s", "t", "r", "i", "n", "g"] ["s", "t", "r", "i", "n", "g"][/COLOR][/COLOR][/CODE] best I have so far. |
Okay: Returned from a camping trip.
Has there been any progress on the project I was working on? |
A quick proposition:
Primes of the form k * b![sup]n[/sup] + 1, where k < b![sup]n[/sup], and where n > 1. (If n were allowed to be 1, every odd prime of the form 6n + 1 would be a prime of the form k * b![sup]n[/sup] + 1.) Or: Simply that k * b![sup]n[/sup] must be divisible by a square number greater than 1. I'll see if all numbers that fit those conditions are present in the OEIS. (Smallest one is 5.) Oh, wait.. Those would be all the 4n + 1 numbers. Nevermind. |
[QUOTE=3.14159;226641]
Or: Simply that k * b![sup]n[/sup] must be divisible by a square number greater than 1.[/QUOTE] this fits: 4x+1 9x+1 16x+1 (variant of 4x+1) 25x+1 and hence only primes^2 need to be used. |
[QUOTE=science_man_88]this fits:
4x+1 9x+1 16x+1 (variant of 4x+1) 25x+1 and hence only primes^2 need to be used.[/QUOTE] [I][B]k * b![sup]n[/sup] + 1, where k < b![sup]n[/sup].[/B][/I] Which means, every 4n + 1 number could not be expressed as k * b![sup]n[/sup] + 1, where k ≤ b![sup]n[/sup] Ex: 7 * 2![sup]2[/sup] + 1 is not a valid number of this form, although it is prime (7 > 4) (7 * 2![sup]2[/sup] + 1 = 29 = p.) Now, I need to hunt numbers of that form and fit them all into a sequence and see if it is already in the OEIS. Note: The n > 1 restriction was found to be unnecessary. The sequence begins: 3, 5, 7, 9, 13, 17, 19, 25, 33, 37, 41, 49, 65..(This is where only b! is allowed, as opposed to any integer b.) 3: 1 * 2!^1 + 1 5: 1 * 2!^2 + 1 (Fermat number) 7: 1 * 3!^1 + 1 9: 1 * 2!^3 + 1 13: 2 * 3!^1 + 1 17: 1 * 2!^4 + 1 (Fermat number) 19: 3 * 3!^1 + 1 25: 4!^1 + 1 33: 2 * 2!^4 + 1 37: 3!^2 + 1 41: 5 * 2!^3 + 1 49: 2 * 4!^1 + 1 65: 4 * 2!^4 + 1 |
I never said [TEX]k*b!^n+1[/TEX] is of form 4x+1 you stated [TEX]k*b!^n/x^2[/TEX] for x>1= integer for some x.
this says that 4x+1 can be a [TEX]k*b!^n+1[/TEX] and same for the rest so really I was just taking your last statement that the statements above and that statement were equal. |
[url]http://www.research.att.com/~njas/sequences/?q=3,5,7,9,11,13,17,19&sort=0&fmt=0&language=english&go=Search[/url]
was the best i could find with all of some group in one sequence. |
note also 65 = 2^6+1=2!^6+1 = 2!^3!+1
|
one thing I notice is the first sequence of difference of your sequence pi is that they all seem to be powers of 2. can you confirm this ?
|
[QUOTE=science_man_88]one thing I notice is the first sequence of difference of your sequence pi is that they all seem to be powers of 2. can you confirm this ?
[/QUOTE] 3, 5: Diff = 2 5, 7: Diff = 2 7, 9: Diff = 2 9, 13: Diff = 2^2 13, 17: Diff = 2^2 17, 19: Diff = 2^2. [B]19, 25: Diff = 6 =/= 2^n.[/B] Strong law of small numbers at work. |
[QUOTE=3.14159;226658]3, 5: Diff = 2
5, 7: Diff = 2 7, 9: Diff = 2 9, 13: Diff = 2^2 13, 17: Diff = 2^2 17, 19: Diff = 2^2. [B]19, 25: Diff = 6 =/= 2^n.[/B] Strong law of small numbers at work.[/QUOTE] okay sorry I forgot I took out 19 lol but the rest all have first difference of power of 2. |
The sieve project is coming along.. Just that we have made zero progress.
Anyone have any spare ideas on it? My best idea is to begin with the k-range loop, then a forprime loop which will be linked to a forstep loop, which, hopefully, will eliminate all the unwanted values. Then, it will save the remaining numbers in a file, and then I make the appropriate modifications to make the range testable, and then proceed to test. |
[CODE]for(k=,,forprime(_=,,forstep(-=,,_,write(,))))[/CODE]
something on the lines of this ? |
Or: I trial-divide each candidate to 1048576, and test those which have no small factors.
[QUOTE=science_man_88]something on the lines of this ? [/QUOTE] Yes. Although I doubt it will work as I want it to. |
The forstep loop will have to contain the liftmod for the primes, to eliminate bad values of k (Those which are divisible by a certain prime p.)
|
I can print the bad values that are divisible by a certain prime p, so far. But I can't get a good enough text editor to remove those specific values.
Ex: 757. [code]623 1380 2137 2894 3651 4408 5165 5922 6679 7436 8193 8950 9707 10464 11221 11978 12735 13492 14249 15006 15763 16520 17277 18034 18791 19548 20305 21062 21819 22576 23333 24090 24847 25604 26361 27118 27875 28632 29389 30146 30903 31660 32417 33174 33931 34688 35445 36202 36959 37716 38473 39230 39987 40744 41501 42258 43015 43772 44529 45286 46043 46800 47557 48314 49071 49828 50585 51342 52099 52856 53613 54370 55127 55884 56641 57398 58155 58912 59669 60426 61183 61940 62697 63454 64211 64968 65725 66482 67239 67996 68753 69510 70267 71024 71781 72538 73295 74052 74809 75566 76323 77080 77837 78594 79351 80108 80865 81622 82379 83136 83893 84650 85407 86164 86921 87678 88435 89192 89949 90706 91463 92220 92977 93734 94491 95248 96005 96762 97519 98276 99033 99790 100547 101304 102061 102818 103575 104332 105089 105846 106603 107360 108117 108874 109631 110388 111145 111902 112659 113416 114173 114930 115687 116444 117201 117958 118715 119472 120229 120986 121743 122500 123257 124014 124771 125528 126285 127042 127799 128556 129313 130070 130827 131584 132341 133098 133855 134612 135369 136126 136883 137640 138397 139154 139911 140668 141425 142182 142939 143696 144453 145210 145967 146724 147481 148238 148995 149752 150509 151266 152023 152780 153537 154294 155051 155808 156565 157322 158079 158836 159593 160350 161107 161864 162621 163378 164135 164892 165649 166406 167163 167920 168677 169434 170191 170948 171705 172462 173219 173976 174733 175490 176247 177004 177761 178518 179275 180032 180789 181546 182303 183060 183817 184574 185331 186088 186845 187602 188359 189116 189873 190630 191387 192144 192901 193658 194415 195172 195929 196686 197443 198200 198957 199714[/code] Those would be the bad k-values for k * 11![sup]4[/sup] + 1, because they form candidates divisible by 757. Proof: 15006 * 11![sup]4[/sup] + 1 = 757 * 50325944549556534016411764332893 |
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. |
[QUOTE=science_man_88;226679][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.[/QUOTE] Yes, vecextract could be used here. I'd just use vector, to be honest: [code]v=vector(#v-1,i,v[i])[/code] replaces v with v without the last element. [QUOTE=science_man_88;226681]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] That's a better solution. |
yeah the bad part for pi is unless there's a known lower bound for his idea then he can't use my second idea. though writing it both ways taught me a lot I think.
|
[QUOTE=science_man_88;226697]yeah the bad part for pi is unless there's a known lower bound for his idea then he can't use my second idea. though writing it both ways taught me a lot I think.[/QUOTE]
Can you explain this in more detail? What does he need a lower bound on? |
well the reason I can set it to a number other than 0 is because i know the first answer already the reason i can change the lower in the loop to 3 is because i know it won't mess up my loop and ironically it's the next value. so unless you know the first time it comes up and possibly the second as the lower bound for a loop it's hard to use if not impossible.
|
[QUOTE=science_man_88;226700]well the reason I can set it to a number other than 0 is because i know the first answer already the reason i can change the lower in the loop to 3 is because i know it won't mess up my loop and ironically it's the next value. so unless you know the first time it comes up and possibly the second as the lower bound for a loop it's hard to use if not impossible.[/QUOTE]
Whoa, man, slow down. Define the problem for me, then what you're doing. Right now I don't know what "it", "the first answer", "the lower", or the "next value" are. |
[QUOTE=CRGreathouse;226702]Whoa, man, slow down. Define the problem for me, then what you're doing. Right now I don't know what "it", "the first answer", "the lower", or the "next value" are.[/QUOTE]
it-the first number put in the vector to initialize it. first answer- the first solution to what the problem is. the lower- the smaller of the 2 values to denote a range given to the variable in the loop. next value- the value after the current value. my code is making a vector that contains only primes- no 0 values. |
| All times are UTC. The time now is 23:20. |
Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2021, Jelsoft Enterprises Ltd.