Created
January 4, 2012 11:52
Revisions
-
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,20 @@ shreyes <- function(temp) ## Cute function that returns the number of iterations that were preformed. { c <- 0 while(temp > 1) { if(temp%%2==0) temp <- temp/2 else temp <- 3*temp + 1 c <- c+1 } return(c) } largest <- 0 num <- 0 system.time(for(i in c(1:1000000)) { iter <- shreyes(i) # Here we get the number of iterations for "i" and we do it for each number from 1 to 1 million if(iter > largest) # If the number of iterations were greater than the previous largest number of iterations { # update the largest number of iterations and store the number in "num" largest <- iter num <- i } })