There is a break() function. Does it not do the job?
-Don
--
Don MacQueen
Lawrence Livermore National Laboratory
7000 East Ave., L-627
Livermore, CA 94550
925-423-1062
On 12/19/12 7:27 AM, "McCloskey, Bryan" wrote:
>Something like this?
>
>n<-1000
>pythag<-function(n){
> for(i in 3:((n-
There is. Use while loops.
---
Jeff NewmillerThe . . Go Live...
DCN:Basics: ##.#. ##.#. Live Go...
Live: OO#.. Dead: OO#.. Playi
Something like this?
n<-1000
pythag<-function(n){
for(i in 3:((n-3)/3))
for(j in (i+1):((n-i)/2))
if(i^2+j^2==(n-i-j)^2) return(i*j*(n-i-j))
}
system.time(print(pythag(n)))
Interesting -- seems to improve speed by ~12%. Not sure if that's
because stop() has more overhead, or if functi
On 12-12-18 1:02 PM, McCloskey, Bryan wrote:
Hey all,
I'm currently working through the problems at Project Euler -- this
question came up while working on Problem 9
(http://projecteuler.net/problem=9):
"A Pythagorean triplet is a set of three natural numbers, a < b < c,
for which, a^2 + b^2 =
Hey all,
I'm currently working through the problems at Project Euler -- this
question came up while working on Problem 9
(http://projecteuler.net/problem=9):
"A Pythagorean triplet is a set of three natural numbers, a < b < c,
for which, a^2 + b^2 = c^2. For example, 3^2 + 4^2 = 9 + 16 = 25 =
5^2
5 matches
Mail list logo