![]() |
[CODE](18:10)>C= vector(100,n,(2*n)!/((n+1)!*n!))
%10 = [1, 2, 5, 14, 42, 132, 429, 1430, 4862, (18:10)>Catalan(n) = return(C[n+1]) %11 = (n)->return(C[n+1]) (18:12)>Catalan(0) %12 = 1 (18:12)>Catalan(2) %13 = 5[/CODE] does this cover [url]http://rosettacode.org/wiki/Catalan_numbers[/url] ? |
I forgot [url]http://www.mersenneforum.org/showthread.php?p=248234#post248234[/url] lead to:
[url]http://rosettacode.org/wiki/Luhn_test_of_credit_card_numbers[/url] done it should be put up. |
sorry for getting off topic again I see a few others that shouldn't be too difficult in the list but anyways.
|
[QUOTE=science_man_88;252712][CODE](18:10)>C= vector(100,n,(2*n)!/((n+1)!*n!))
%10 = [1, 2, 5, 14, 42, 132, 429, 1430, 4862, (18:10)>Catalan(n) = return(C[n+1]) %11 = (n)->return(C[n+1]) (18:12)>Catalan(0) %12 = 1 (18:12)>Catalan(2) %13 = 5[/CODE] does this cover [url]http://rosettacode.org/wiki/Catalan_numbers[/url] ?[/QUOTE] Sure, that'll do -- as long as you don't want Catalan(100) or higher. (Edit: I see that the link suggests memoization, in which case you did it right. As it happens it's probably not needed here.) I would just do [code]Catalan(n)=(2*n)!/(n+1)!/n![/code] or, probably faster, [code]Catalan(n)=binomial(2*n,n+1)/n[/code] |
[QUOTE=science_man_88;252720]I forgot [url]http://www.mersenneforum.org/showthread.php?p=248234#post248234[/url] lead to:
[url]http://rosettacode.org/wiki/Luhn_test_of_credit_card_numbers[/url] done it should be put up.[/QUOTE] Great, put it up! [QUOTE=science_man_88;252736]sorry for getting off topic again I see a few others that shouldn't be too difficult in the list but anyways.[/QUOTE] You can do them if you like, or post it here if you want feedback. |
[QUOTE=CRGreathouse;252751]Great, put it up!
You can do them if you like, or post it here if you want feedback.[/QUOTE] well I kinda see the math of the sierpinski triangle and carpet going up a step from the triangle shown means multiplying the width by 3 and printing 8/9 of the previous carpet and leaving the center clear. since they show examples with them hitting the smallest possible it's simply working backwards I think. |
[CODE](20:28)>sdsub(x,y) = C=y;for(a=1,#C,C[a]=x[C[a]+1]);C=vecsort(C);for(b=1,#y,x[y[b]+1]=C[b]);x;
(20:48)>sdsub([7, 6, 5, 4, 3, 2, 1, 0],[6, 1, 7]) %94 = [7, 1, 5, 4, 3, 2, 0, 6][/CODE] this is trying : [url]http://rosettacode.org/wiki/Sort_disjoint_sublist[/url] it seems to reverse 2 thing as it places them. oh never mind I see why trying out the simpler solution they suggest, it's because the call to a unsorted y. |
I think this is what PARI's indirect sorting is for. Take the elements you want to sort into a new vector, call it u, and sort with vecsort(u,,1). Rather than sorting u, this will return a vector that tells you where to put the elements. Then you can just put each element where the resulting vector tells you to put it.
|
[QUOTE=CRGreathouse;252861]I think this is what PARI's indirect sorting is for. Take the elements you want to sort into a new vector, call it u, and sort with vecsort(u,,1). Rather than sorting u, this will return a vector that tells you where to put the elements. Then you can just put each element where the resulting vector tells you to put it.[/QUOTE]
[CODE](21:28)>vecsort([1,2,3],,1) %134 = Vecsmall([1, 2, 3]) (21:30)>vecsort([1,2,3],,2) %135 = [1, 2, 3] (21:30)>vecsort([1,2,3],,3) %136 = Vecsmall([1, 2, 3]) (21:33)>vecsort([1,2,3],,4) %137 = [3, 2, 1] (21:33)>vecsort([1,2,3],,5) %138 = Vecsmall([3, 2, 1]) (21:33)>vecsort([1,2,3],,6) %139 = [3, 2, 1] (21:33)>vecsort([1,2,3],,7) %140 = Vecsmall([3, 2, 1]) (21:33)>vecsort([1,2,3],,8) %141 = [1, 2, 3] (21:33)>vecsort([1,2,3],,9) %142 = Vecsmall([1, 2, 3]) (21:34)>vecsort([1,2,3],,10) %143 = [1, 2, 3][/CODE] |
[CODE](21:25)>sdsub1(x,y) = D=y;C=y;for(a=1,#C,C[a]=x[C[a]]);C=vecsort(C);D=vecsort(D);for(b=1,#y,x[D[b]]=C[b]);x;
(21:28)>sdsub1([7, 6, 5, 4, 3, 2, 1, 0],[7,2,8])[/CODE] okay this works for the 1 based what if I want it to act like it's 0 based. |
[QUOTE=science_man_88;252865]%134 = Vecsmall([1, 2, 3])
(21:30)>vecsort([1,2,3],,2) %135 = [1, 2, 3] (21:30)>vecsort([1,2,3],,3) %136 = Vecsmall([1, 2, 3]) (21:33)>vecsort([1,2,3],,4) %137 = [3, 2, 1] (21:33)>vecsort([1,2,3],,5) %138 = Vecsmall([3, 2, 1]) (21:33)>vecsort([1,2,3],,6) %139 = [3, 2, 1] (21:33)>vecsort([1,2,3],,7) %140 = Vecsmall([3, 2, 1]) (21:33)>vecsort([1,2,3],,8) %141 = [1, 2, 3] (21:33)>vecsort([1,2,3],,9) %142 = Vecsmall([1, 2, 3]) (21:34)>vecsort([1,2,3],,10) %143 = [1, 2, 3][/CODE][/QUOTE] Not ,,2. Not ,,3. The flag you want to set is 1 and none of the others. (You can see what they do by reading the manual, or get an overview with ?vecsort, but they're not applicable here.) |
| All times are UTC. The time now is 23:00. |
Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2021, Jelsoft Enterprises Ltd.