![]() |
|
|
#2124 |
|
"Forget I exist"
Jul 2009
Dumbassville
26·131 Posts |
I was also thinking of making a Cartesian product making script but my main problem is I don't know how to allow for infinite arguments in the function. I guess I could make one that worked for 2 at a time, and puts the parentheses around it with a complete argument. what am i saying I can make it so the person has to give a collection of sets doh.
Last fiddled with by science_man_88 on 2011-02-04 at 15:11 |
|
|
|
|
|
#2125 |
|
"Forget I exist"
Jul 2009
Dumbassville
26·131 Posts |
Code:
(12:17)>p=[1,2];c=[1,2];d=[];for(i=1,#p,for(j=1,#c,x=[p[i],c[j]];d=concat(d,[x]))) (12:17)>d %201 = [[1, 1], [1, 2], [2, 1], [2, 2]] (12:17)>p=[1,2];e=[];for(i=1,#p,for(j=1,#d,x=[d[j],p[i]];e=concat(e,[x]))) (12:17)>e %202 = [[[1, 1], 1], [[1, 2], 1], [[2, 1], 1], [[2, 2], 1], [[1, 1], 2], [[1, 2], 2], [[2, 1], 2], [[2, 2], 2]] |
|
|
|
|
|
#2126 |
|
"Forget I exist"
Jul 2009
Dumbassville
203008 Posts |
Code:
(12:34)>Cp(p,c)= d=[];for(i=1,#p,for(j=1,#c,x=[p[i],c[j]];d=concat(d,[x]))) %205 = (p,c)->d=[];for(i=1,#p,for(j=1,#c,x=[p[i],c[j]];d=concat(d,[x]))) (12:39)>Cp([1,3],[1,2]) (12:39)>d %206 = [[1, 1], [1, 2], [3, 1], [3, 2]] (12:39)>CPC(C)= A=Cp(C[1],C[2]);B=[];for(i=3,#C,if(i%2==1,B=Cp(A,C[i]),A=Cp(B,C[i])));if(#C%2==1,return(B),return(A)) %207 = (C)->A=Cp(C[1],C[2]);B=[];for(i=3,#C,if(i%2==1,B=Cp(A,C[i]),A=Cp(B,C[i])));if(#C%2==1,return(B),return(A)) (12:43)>C=[v,c] %208 = [[1, 2, 3, 4, 5, 6, 7, 8], [1, 2]] (12:44)>CPC(C) %209 = 0 |
|
|
|
|
|
#2127 | |
|
"Forget I exist"
Jul 2009
Dumbassville
26·131 Posts |
Quote:
Code:
CPC(C)= Cp(C[1],C[2]);A=d;for(i=3,#C,Cp(A,C[i]);A=d);A; |
|
|
|
|
|
|
#2128 |
|
"Forget I exist"
Jul 2009
Dumbassville
203008 Posts |
Code:
(14:31)>intersection(x,y) = C=[];for(i=1,#x,for(j=1,#y,if(x[i]==y[j],C=concat(C,x[i]))));C; (14:33)>intersection([1,2,3,1],[2,3,1]) %259 = [1, 2, 3, 1] |
|
|
|
|
|
#2129 | ||
|
Aug 2006
10111010110112 Posts |
Yes. You should be returning the result,though, not storing it in a variable. What if you needed to call it twice, like
dostuff(Cp(v1, v2), Cp(v3, v4)) ? Quote:
Maybe this: Code:
printVectorAsSet(v)={
if(type(v) != "t_VEC",
print1(v)
,
print1("{");
if (#v, printVectorAsSet(v[1]));
for(i=2,#v,
print1(", ");
printVectorAsSet(v[i])
);
print1("}")
)
}
Code:
[[10, 1], [10, 2], [20, 1], [20, 2], [30, 1], [30, 2]] Code:
{{10, 1}, {10, 2}, {20, 1}, {20, 2}, {30, 1}, {30, 2}}
Quote:
I'll admit, I don't like the repetition. I suppose for both functions you could add vecsort(__,,8) in the appropriate places to fix that. |
||
|
|
|
|
|
#2130 | |
|
"Forget I exist"
Jul 2009
Dumbassville
26×131 Posts |
Quote:
Code:
intersection(x,y) = C=[];for(i=1,#x,for(j=1,#y,if(x[i]==y[j],C=concat(C,x[i]))));printVectorAsSet(vecsort(C,,8)); Last fiddled with by science_man_88 on 2011-02-04 at 21:44 |
|
|
|
|
|
|
#2131 | |
|
"Forget I exist"
Jul 2009
Dumbassville
203008 Posts |
applying your make to a set function to the CPC gives back:
Code:
{{{1, 1}, 1}, {{1, 1}, 2}, {{1, 2}, 1}, {{1, 2}, 2}, {{2, 1}, 1}, {{2, 1}, 2}, {{2, 2}, 1}, {{2, 2}, 2}, {{3, 1}, 1}, {{3, 1}, 2}, {{3, 2}, 1}, {{3, 2}, 2}, {{4, 1}, 1}, {{4, 1}, 2}, {{4, 2}, 1}, {{4, 2}, 2}, {{5, 1}, 1}, {{5, 1}, 2}, {{5, 2}, 1}, {{5, 2}, 2}, {{6, 1}, 1}, {{6, 1}, 2}, {{6, 2}, 1}, {{6, 2}, 2}, {{7, 1}, 1}, {{7, 1}, 2}, {{7, 2}, 1}, {{7, 2}, 2}, {{8, 1}, 1}, {{8, 1}, 2}, {{8, 2}, 1}, {{8, 2}, 2}}
Quote:
Code:
aredisjoint(A=[],B=[]) =
if(#A!=0 && #B!=0,
a=0;
for(i=1,#A,
for(j=1,#B,
if(A[i]==B[j],
return(0),
a=a+1;
if(a==#A*#B,
return(1)
)
)
)
),
return(0)
)
addhelp(aredisjoint,"a function to tell when 2 sets (vectors(which are actually sequences)) are considered disjoint.")
Last fiddled with by science_man_88 on 2011-02-04 at 22:04 |
|
|
|
|
|
|
#2132 |
|
Aug 2006
3×1,993 Posts |
Looks like you missed a parenthesis.
|
|
|
|
|
|
#2133 |
|
"Forget I exist"
Jul 2009
Dumbassville
20C016 Posts |
|
|
|
|
|
|
#2134 | |
|
"Forget I exist"
Jul 2009
Dumbassville
100000110000002 Posts |
Quote:
Last fiddled with by science_man_88 on 2011-02-05 at 00:00 |
|
|
|
|
![]() |
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 |