Factors of an integer: Difference between revisions
Content added Content deleted
ReeceGoding (talk | contribs) (→{{header|R}}: Filter solution) |
ReeceGoding (talk | contribs) |
||
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, |
<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: |