python,sequence,primes,collatz,memorization

Your existing code is incorrectly indented. I assume this task is a homework task, so I won't post a complete working solution, but I'll give you some helpful snippets. First, here's a slightly more efficient primality tester. Rather than testing if all numbers less than a are factors of a,...

r,function,outliers,memorization

You just need to update temp for any indices that aren't outliers: test <- function(x) { temp <- x[1] st1 <- numeric(length(x)) for (i in 2:(length(x))){ if(!is.na(x[i]) & !is.na(x[i-1]) & abs(x[i]-temp) > 20) { st1[i] <- 1 } else { temp <- x[i] } } return(st1) } myts[,2] <- apply(as.data.frame(myts[,1]),2,test)...