I am trying to find the smallest number that evenly divides 1:20. I created a function, and this is what I have:
smallestN<- function(a,b) {
i<- 1
repeat {
if (all(i%%a:b == 0)) {
break
} else {
i<-i+1
}
}
return(i)
}
It works great for short intervals, but for 1:20 it takes a lot of time. How can I improve my code to make it faster?
source
share