![]() |
It's so much nicer if you format the code!
[code]{b=2; forprime(p=2,2281, for(y=1,p-1, trap(, print("break here, p="p", y="y); break , b=sqrt(Mod(b,1<<p-1)) ); if(y==p-1,print(p)) ); b=2 )}[/code] I can't figure out the intent either. |
after coming across a comment at:
[url]https://oeis.org/A002450[/url] I did some searching about the topic and came across a reference to Sierpinski triangle and rule 90 with that I was able to get to this: [CODE](n)-> a=[[[1,1,1],0],[[1,1,0],1],[[1,0,1],0],[[1,0,0],1],[[0,1,1],1],[[0,1,0],0],[[0,0,1],1],[[0,0,0],0]]; b=matrix(2^(n-1)+2,2^n-1+2); b[2,(#b+1)/2]=1; for(x=3,2^(n-1)-1, for(y=2,#b-3, for(z=1,#a, if(a[z][2]==1, b[x,y+1]=a[z][2] ) ) ) ) ;b[/CODE] as a almost working code to make the Sierpinski triangle Wikipedia helped in my understanding a bit as well as playing around, but my problem is the if statement in the last for loop I want to check the three I need to get the ones and zeroes in the correct placement for what my layout should be ( and yes my layout has a border, no that's actually not what I checked before I just did that as a test case). according to [url]http://rosettacode.org/wiki/Reports:Tasks_not_implemented_in_PARI/GP[/url] the triangle has still not been done. |
[CODE](19:29)>Sierpinski(4)
%352 = [0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0] [0 0 0 0 0 0 0 0 [COLOR="Red"]1[/COLOR] 0 0 0 0 0 0 0 0] [0 0 0 0 0 0 0 [COLOR="Red"]1 0 1[/COLOR] 0 0 0 0 0 0 0] [0 0 0 0 0 0 [COLOR="Red"]1 0 0 0 1[/COLOR] 0 0 0 0 0 0] [0 0 0 0 0 [COLOR="Red"]1 0 1 0 1 0 1[/COLOR] 0 0 0 0 0] [0 0 0 0 [COLOR="Red"]1 0 0 0 0 0 0 0 1[/COLOR] 0 0 0 0] [0 0 0 [COLOR="Red"]1 0 1 0 0 0 0 0 1 0 1[/COLOR] 0 0 0] [0 0 [COLOR="Red"]1 0 0 0 1 0 0 0 1 0 0 0 1[/COLOR] 0 0] [0 [COLOR="Red"]1 0 1 0 1 0 1 0 1 0 1 0 1 0 1[/COLOR] 0] [0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0][/CODE] just realized this wasn't it, [CODE](n)-> a=[[[1,1,1],0],[[1,1,0],1],[[1,0,1],0],[[1,0,0],1],[[0,1,1],1],[[0,1,0],0],[[0,0,1],1],[[0,0,0],0]]; b=matrix(2^(n-1)+2,2^n-1+2); b[2,(#b+1)/2]=1; for(x=3,2^(n-1)+1, for(y=1,#b-2, for(z=1,#a, if(eval(Vec(Str(b[x-1,y]b[x-1,y+1]b[x-1,y+2])))==a[z][1], b[x,y+1]=a[z][2] ) ) ) ) ;b[/CODE] never mind it's the way I printed it that got me confused this is it. and it works for all n>=1 I believe. |
[QUOTE=cmd;282102]3 .. Spring roll s in ..
:bear:[/QUOTE] [CODE]x=1000000000;d=#divisors(x);for(y=1,ceil(d/2),print(divisors(x)[y]"\t\t\t "divisors(x)[d-(y-1)]))[/CODE] is my best version of it except I only list everything once. |
working with matrices
[CODE](09:30)>a=matrix(10,2);print(#a[,1]);print(#a);
10 2[/CODE] |
is there an easy way to create all the distinct partitions of a number n without the number 1 involved ( though I also have a way with 1 involved I think) ? because I'm trying to speed up my aligen function and it's based on partitions.
|
[QUOTE=science_man_88;284065]is there an easy way to create all the distinct partitions of a number n without the number 1 involved ( though I also have a way with 1 involved I think) ? because I'm trying to speed up my aligen function and it's based on partitions.[/QUOTE]
looks to be a no there's ways of counting them but I want the partitions themselves because working backwards through aliquot sequences can be based in partitions of n-1 where n is the number we are saying is sigma(x)-x ( my current script does checks) for example: n=6; a=n-1=5; a=5=4+1=3+2 the 5 is by itself so square it, then we without duplicating the 1 we took off we get get 5^2,3*2 , gives you 25 and 6 and only those as 5 can't be partitioned in h>3 parts without a 1 being involved. a sigma check on both shows they both work out . |
[CODE]homeprime(n)= s=n;until(isprime(s),a=factor(s);b="";for(x=1,#a[,2],until(a[x,2]==0,b=concat(b,Str(a[x,1]));a[x,2]=a[x,2]-1));print(b);s=eval(b))[/CODE]
made this after reading in the HP(49) thread. which gave me links to learn about home primes. |
[QUOTE=science_man_88;284065]is there an easy way to create all the distinct partitions of a number n without the number 1 involved ( though I also have a way with 1 involved I think) ? because I'm trying to speed up my aligen function and it's based on partitions.[/QUOTE]
Here's some naive code: [code]partNo1(n)={ select(v->vecmin(v)>1,partitions(n)) }; partNo1Count(n)=polcoeff((1-'x)/eta('x+'x*O('x^n)), n);[/code] If you're running an old version of gp (you probably are), you'll need to change the order of the arguments in select. If you don't like the Vecsmall appearing in the output, apply Vec to each member. Both changes:[code]partNo1(n)={ apply(Vec,select(partitions(n),v->vecmin(v)>1)) };[/code] |
[QUOTE=CRGreathouse;291835]Here's some naive code:
[code]partNo1(n)={ select(v->vecmin(v)>1,partitions(n)) }; partNo1Count(n)=polcoeff((1-'x)/eta('x+'x*O('x^n)), n);[/code] If you're running an old version of gp (you probably are), you'll need to change the order of the arguments in select. If you don't like the Vecsmall appearing in the output, apply Vec to each member. Both changes:[code]partNo1(n)={ apply(Vec,select(partitions(n),v->vecmin(v)>1)) };[/code][/QUOTE] I got back that partitions is not a function. |
[QUOTE=science_man_88;291861]I got back that partitions is not a function.[/QUOTE]
this gets too complicated really quick: duplication through permutation is a problem that can up, so was the avoiding using 1's so are the ones with 2 of the same number. so many things to consider, no wonder a lot of people take the other routes. for my purposes 2,3==3,2 1's are unnecessary because I already subtract it from n, the duplicate part means any partition with x,x in it becomes unwanted. |
| All times are UTC. The time now is 22:48. |
Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2021, Jelsoft Enterprises Ltd.