Multifactorial: Difference between revisions
Content added Content deleted
(Added solution for Action!) |
ReeceGoding (talk | contribs) m (→{{header|R}}: Syntax highlighting.) |
||
Line 1,661: | Line 1,661: | ||
=={{header|R}}== |
=={{header|R}}== |
||
===Recursive solution=== |
===Recursive solution=== |
||
<lang |
<lang rsplus>#x is Input |
||
#n is Factorial Number |
#n is Factorial Number |
||
multifactorial=function(x,n){ |
multifactorial=function(x,n){ |
||
Line 1,672: | Line 1,672: | ||
===Sequence solution=== |
===Sequence solution=== |
||
This task doesn't use big enough numbers to need efficient code, so R can solve this very succinctly. |
This task doesn't use big enough numbers to need efficient code, so R can solve this very succinctly. |
||
<lang |
<lang rsplus>mfact<-function(n,deg){prod(seq(from = n, to = 1, by = -deg))} |
||
outer(1:10,1:5,Vectorize(mfact))</lang> |
outer(1:10,1:5,Vectorize(mfact))</lang> |
||
If we really insist on a pretty table, then we can add some names and transpose the output. |
If we really insist on a pretty table, then we can add some names and transpose the output. |
||
<lang |
<lang rsplus>mfact<-function(n,deg){prod(seq(from = n, to = 1, by = -deg))} |
||
n<-1:10; names(n)<-n |
n<-1:10; names(n)<-n |
||
deg<-1:5; names(deg)<-paste("Degree",deg) |
deg<-1:5; names(deg)<-paste("Degree",deg) |