Skip to content

Instantly share code, notes, and snippets.

@jasper-lyons
Created December 11, 2017 09:44
Show Gist options
  • Save jasper-lyons/33d5134d072516727435d7e5c6baae26 to your computer and use it in GitHub Desktop.
Save jasper-lyons/33d5134d072516727435d7e5c6baae26 to your computer and use it in GitHub Desktop.
storage <- list()
numbers <- c(4, 1, 15, 12, 0, 9, 9, 5, 5, 8, 7, 3, 14, 5, 12, 3)
count <- 0
while (!(list(numbers) %in% storage)) {
storage <- append(storage, list(numbers))
largest <- max(numbers)
largestIndex <- which.max(numbers)
numbers[largestIndex] = 0
index <- largestIndex
while (largest > 0) {
index <- (index %% length(numbers)) + 1
numbers[index] <- numbers[index] + 1
largest <- largest - 1
}
count <- count + 1
}
print(numbers)
print(storage)
print(count)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment