Argh! The second (concise) version should have |, not & !!! -s
On 2/24/09, Stavros Macrakis <macra...@alum.mit.edu> wrote: > "L'esprit de l'escalier" strikes again.... > > An even simpler statement of your original problem: > > Find the factors that A and B have in common. > > If A and B are fairly small (< 1e7, say), a very direct approach is: > > which( ! (A %% 1:min(A,B)) & !(B %% 1:min(A,B)) ) > > Is this "brute force"? Well, I suppose, but it is simple and direct > and fast enough for A=B=1e7 (5 sec). It doesn't involve factorization > into prime factors, GCDs, or combinations. > > If your goal is concision and not clarity or speed, you can do even better: > > which( !(A %% 1:B & B %% 1:A) ) > > which is still practical (though it gives a warning). > > How big do your A and B get, and how many different A's and B's do you > need to run this calculation for? > > -s > ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.