![]() |
|
|
#2135 |
|
Aug 2006
597910 Posts |
I don't get that, or any, error. (The program doesn't seem to do what you want, but that's another matter,)
|
|
|
|
|
|
#2136 | |
|
"Forget I exist"
Jul 2009
Dumbassville
26×131 Posts |
Quote:
Code:
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)) |
|
|
|
|
|
|
#2137 |
|
"Forget I exist"
Jul 2009
Dumbassville
26×131 Posts |
I find something weird if I had it in fancy form I was always "missing something" if not it worked fine.
Last fiddled with by science_man_88 on 2011-02-05 at 12:21 |
|
|
|
|
|
#2138 |
|
Aug 2006
3·1,993 Posts |
Maybe you didn't use braces, so it read each line individually?
I always write my functions like Code:
foo={
\\ . . .
};
|
|
|
|
|
|
#2139 |
|
"Forget I exist"
Jul 2009
Dumbassville
20C016 Posts |
|
|
|
|
|
|
#2140 |
|
Aug 2006
3·1,993 Posts |
If you don't use them then each line will be interpreted individually. When you type a command and press enter, it does it right away instead of waiting for another line. So you 'knew', really, that it worked that way -- you just never quite associated the two.
But really, do write your functions out in full form. You often seem to get frustrated with others when they don't respond to your posts, but that's one big reason they don't -- it's too hard to figure out what's going on in your scripts. When you make it easy for other people to read they're more likely to read them and hence respond. Last fiddled with by CRGreathouse on 2011-02-05 at 22:43 |
|
|
|
|
|
#2141 | |
|
"Forget I exist"
Jul 2009
Dumbassville
26·131 Posts |
Quote:
Code:
aredisjoint(A=[],B=[]) ={
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.")
ispd(C) ={
b=0;
for(i=1,#C,
for(j=1,#C,
if(i!=j && aredisjoint(C[i],C[j]),
b=b+1
)
)
);
if(b==#C*#C-#C,
return(1),
return(0)
)
};
addhelp(ispd,"a function to tell when a collection of sets (vectors(which are actually sequences)) is considered pairwise disjoint.")
CPC(C)={
Cp(C[1],C[2]);
A=d;
for(i=3,#C,
Cp(A,C[i]);
A=d
);
printVectorAsSet(A) };
addhelp(CPC,"a function to create the cartesian product of a collection of sets.")
Cp(p,c)={
d=[];
for(i=1,#p,
for(j=1,#c,
x=[p[i],c[j]];
d=concat(d,[x])
)
);
d;};
addhelp(Cp,"a function to create the cartesian product of 2 sets.")
printVectorAsSet(v)={
if(type(v) != "t_VEC",
print1(v)
,
print1("{");
if (#v, printVectorAsSet(v[1]));
for(i=2,#v,
print1(", ");
printVectorAsSet(v[i])
);
print1("}")
)
}
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)); };
|
|
|
|
|
|
|
#2142 |
|
Aug 2006
597910 Posts |
aredisjoint([1,2,3],[4,5]) returns 0.
|
|
|
|
|
|
#2143 |
|
"Forget I exist"
Jul 2009
Dumbassville
26·131 Posts |
okay I added a new thing to that and on my end it works it's and if loop checking if #a and #b are = 0 but that shouldn't make a difference in that:
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)
)};
Last fiddled with by science_man_88 on 2011-02-05 at 23:41 |
|
|
|
|
|
#2144 | |
|
"Forget I exist"
Jul 2009
Dumbassville
20C016 Posts |
Quote:
Code:
union(A,B)=concat(A,B);vecsort(union,,8) Code:
union(A,B)= U=concat(A,B);vecsort(U,,8) Last fiddled with by science_man_88 on 2011-02-06 at 00:35 |
|
|
|
|
|
|
#2145 |
|
"Forget I exist"
Jul 2009
Dumbassville
26·131 Posts |
Just to update I've changed one thing in Cp and fixed the output for CPC.
hopefully I can program more of this it may become very useful. |
|
|
|
![]() |
| 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 |