General FizzBuzz: Difference between revisions
Content added Content deleted
(Added solution for Action!) |
ReeceGoding (talk | contribs) m (→{{header|R}}: Syntax highlighting.) |
||
Line 3,034: | Line 3,034: | ||
===... solution=== |
===... solution=== |
||
The task asks that we assume 3 factors for the sake of simplicity. However, R makes the k factors case not much more complicated, so we will do that. The only major downside is that checking for malformed user input becomes so difficult that we will not bother. |
The task asks that we assume 3 factors for the sake of simplicity. However, R makes the k factors case not much more complicated, so we will do that. The only major downside is that checking for malformed user input becomes so difficult that we will not bother. |
||
<lang |
<lang rsplus>genFizzBuzz <- function(n, ...) |
||
{ |
{ |
||
args <- list(...) |
args <- list(...) |
||
Line 3,055: | Line 3,055: | ||
===Names solution=== |
===Names solution=== |
||
If we deviate from the task's example of how to input parameters and instead use R's names facilities to make our (number, name) pairs, we get a much cleaner solution. |
If we deviate from the task's example of how to input parameters and instead use R's names facilities to make our (number, name) pairs, we get a much cleaner solution. |
||
<lang |
<lang rsplus>namedGenFizzBuzz <- function(n, namedNums) |
||
{ |
{ |
||
factors <- sort(namedNums)#Required by the task: We must go from least factor to greatest. |
factors <- sort(namedNums)#Required by the task: We must go from least factor to greatest. |