Factors of an integer: Difference between revisions

Content added Content deleted
(→‎{{header|R}}: Filter solution)
Line 4,470: Line 4,470:
===Filter solution===
===Filter solution===
With identical output, a more idiomatic way is to use R's Filter and Vectorize:
With identical output, a more idiomatic way is to use R's Filter and Vectorize:
<lang R>factors<-function(n){Filter(function(x) n %% x == 0, x=c(1:(n%/%2),n))}
<lang R>factors<-function(n){c(Filter(function(x) n %% x == 0, 1:(n%/%2)),n)}


#If you want to use a vector of integers as an input, as in the previous solution, use:
#If you want to use a vector of integers as an input, as in the previous solution, use: