Proper divisors: Difference between revisions
→Filter solution: Clean-up.
ReeceGoding (talk | contribs) m (→{{header|R}}: Syntax highlighting.) |
ReeceGoding (talk | contribs) (→Filter solution: Clean-up.) |
||
Line 4,918:
===Filter solution===
<lang rsplus>#Task 1
properDivisors <-
▲ if(n==1) NULL else Filter(function(x) n %% x == 0, 1:(n%/%2))
#Task 2
Vectorize(properDivisors)(1:10)
Line 4,934 ⟶ 4,928:
#Be aware that this solution uses both length and lengths. It would not work if the index of the
#desired number was not also the number itself. However, this is always the case.
mostProperDivisors <- function(N)
{
divisorList <- Vectorize(properDivisors)(
numberWithMostDivisors <- which.max(lengths(divisorList))
" proper divisors.")
}
mostProperDivisors(20000)</lang>
Line 4,948 ⟶ 4,943:
> Vectorize(properDivisors)(1:10)
[[1]]
integer(0)
[[2]]
|