Left factorials: Difference between revisions

→‎Vectorization solution: Removed need to check for n=0.
(→‎Vectorization solution: Removed need to check for n=0.)
Line 2,907:
leftFact <- function(numbs)
{
#As we will never actually use the numeric values of our outputs, we will
#we will immediately coerce them to characters. For technical reasons to do with
#reasons to do with nchar misbehaving, this also makes task 3 much easier.
#As task 1 will demonstrate, the n=0 special case is covered.
#much easier.
sapply(numbs, function(n) as.character(if(n==0) 0 else sum(factorialZ(0:seq_len(n)-1)))))
}
printer <- function(inputs) print(data.frame(Value = leftFact(inputs), row.names = paste0("!", inputs)))
331

edits