Created
October 23, 2018 07:50
-
-
Save gregoriobenatti/e6b817333c950b25f7c3dda2e1520950 to your computer and use it in GitHub Desktop.
FizzBuzz
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- CPP | |
#include <iostream> | |
int main() | |
{ | |
for(int i=1;i<=100;i++) | |
{ | |
if (i%15==0) | |
std::cout << "FizzBuzz" << std::endl; | |
else if (i%5==0) | |
std::cout << "Buzz" << std::endl; | |
else if (i%15==0) | |
std::cout << "FizzBuzz" << std::endl; | |
else | |
std::cout << i << std::endl; | |
} | |
return 0; | |
} | |
-- Lua | |
for i = 1, 100 do | |
if i % 3 == 0 and i % 5 == 0 then | |
print "FizzBuzz" | |
elseif i % 3 == 0 then | |
print "Fizz" | |
elseif i % 5 == 0 then | |
print "Buzz" | |
else | |
print(i) | |
end | |
end | |
-- Javascript | |
for (var i = 1; i <= 100; i++) { | |
var f = i % 3 == 0, b = i % 5 == 0; | |
console.log(f ? b ? "FizzBuzz" : "Fizz" : b ? "Buzz" : i); | |
} | |
-- Python (https://stackoverflow.com/questions/22743860/python-fizzbuzz) | |
def FizzBuzz(): | |
for i in range(1,101): | |
print { | |
3 : "Fizz", | |
5 : "Buzz", | |
15 : "FizzBuzz"}.get(15*(not i%15) or | |
5*(not i%5 ) or | |
3*(not i%3 ), '{}'.format(i)) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment