Skip to content

Instantly share code, notes, and snippets.

@isomorphisms
Created August 29, 2014 07:02
Show Gist options
  • Save isomorphisms/136efd85d69b59cb6794 to your computer and use it in GitHub Desktop.
Save isomorphisms/136efd85d69b59cb6794 to your computer and use it in GitHub Desktop.
fizzbuzz
fb = function(n) {
f = ""
b = ""
if (!n %%3) f="fizz"
if (!n %%5) b="buzz"
print(paste0(f,b))
}
for (n in seq.int(1,100) ) fb(n)
@isomorphisms
Copy link
Author

golfy version: sapply(1:100,function(x)ifelse(!x%%3,if(!x%%5)'FizzBuzz'else'Fiz',if(!x%%5)'Buzz'else x)

Could it be shorter with a paste?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment