Problem 39

Problem 39 - Project Euler

is.right <- function(a,b,c) a^2 == (b^2 + c^2)

max.count <- 0
max.num <- 0

for(i in seq(12, 998, by=2)){
  count <- 0
  for(j in floor(i/3):(i/2)){
    for(k in 1:((i-j)/2)){
      if(is.right(j, k, i-j-k)) count <- count + 1
    }
  }
  if(count > max.count){
    max.count <- count
    max.num <- i
  }
}

これはひどい