Sunday, 2 June 2013

Project Euler #29 in R

Project Euler #29 in R

I'm trying to implement a solution to the following problem: For a in [1,100] and b in [1,100], do a^b for every a and b. How many unique results we can obtain?
In Python I can solve this problem and I get the correct answer, but when I try a R implementation I can't get the correct answer.
Here's my code:
lista=c()
for (b in 2:100){
  for (a in 2:100){
    elemento=a^b
    if (!is.element(elemento,lista)){
      lista=c(lista,elemento)
    }
  }
}


print(length(lista))

No comments:

Post a Comment