Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
18
Task/General-FizzBuzz/R/general-fizzbuzz-1.r
Normal file
18
Task/General-FizzBuzz/R/general-fizzbuzz-1.r
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
genFizzBuzz <- function(n, ...)
|
||||
{
|
||||
args <- list(...)
|
||||
#R doesn't like vectors of mixed types, so c(3, "Fizz") is coerced to c("3", "Fizz"). We must undo this.
|
||||
#Treating "[[" as if it is a function is a bit of R's magic. You can treat it like a function because it actually is one.
|
||||
factors <- as.integer(sapply(args, "[[", 1))
|
||||
words <- sapply(args, "[[", 2)
|
||||
sortedPermutation <- sort.list(factors)#Required by the task: We must go from least factor to greatest.
|
||||
factors <- factors[sortedPermutation]
|
||||
words <- words[sortedPermutation]
|
||||
for(i in 1:n)
|
||||
{
|
||||
isFactor <- i %% factors == 0
|
||||
print(if(any(isFactor)) paste0(words[isFactor], collapse = "") else i)
|
||||
}
|
||||
}
|
||||
genFizzBuzz(105, c(3, "Fizz"), c(5, "Buzz"), c(7, "Baxx"))
|
||||
genFizzBuzz(105, c(5, "Buzz"), c(9, "Prax"), c(3, "Fizz"), c(7, "Baxx"))
|
||||
13
Task/General-FizzBuzz/R/general-fizzbuzz-2.r
Normal file
13
Task/General-FizzBuzz/R/general-fizzbuzz-2.r
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
namedGenFizzBuzz <- function(n, namedNums)
|
||||
{
|
||||
factors <- sort(namedNums)#Required by the task: We must go from least factor to greatest.
|
||||
for(i in 1:n)
|
||||
{
|
||||
isFactor <- i %% factors == 0
|
||||
print(if(any(isFactor)) paste0(names(factors)[isFactor], collapse = "") else i)
|
||||
}
|
||||
}
|
||||
namedNums <- c(Fizz=3, Buzz=5, Baxx=7)#Notice that we can name our inputs without a function call.
|
||||
namedGenFizzBuzz(105, namedNums)
|
||||
shuffledNamedNums <- c(Buzz=5, Prax=9, Fizz=3, Baxx=7)
|
||||
namedGenFizzBuzz(105, shuffledNamedNums)
|
||||
Loading…
Add table
Add a link
Reference in a new issue