Last active
March 17, 2017 19:12
-
-
Save nickserv/8676996 to your computer and use it in GitHub Desktop.
FizzBuzz in various languages
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
*.class | |
a.out | |
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
#include <stdio.h> | |
int main() { | |
int i; | |
for(i = 0; i <= 100; i++) { | |
if(i % 15 == 0) { | |
printf("FizzBuzz\n"); | |
} | |
else if(i % 3 == 0) { | |
printf("Fizz\n"); | |
} | |
else if(i % 5 == 0) { | |
printf("Buzz\n"); | |
} | |
else { | |
printf("%d\n", i); | |
} | |
} | |
return 0; | |
} |
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
package main | |
import("fmt") | |
func is_divisible(x int, y int) bool { | |
return x % y == 0 | |
} | |
func show_int(x int) string { | |
switch { | |
case is_divisible(x, 15): | |
return "FizzBuzz" | |
case is_divisible(x, 3): | |
return "Fizz" | |
case is_divisible(x, 5): | |
return "Buzz" | |
default: | |
return fmt.Sprintf("%d", x) | |
} | |
} | |
func main() { | |
for i := 0; i <= 100; i++ { | |
fmt.Println(show_int(i)) | |
} | |
} |
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
divisible :: Int -> Int -> Bool | |
divisible x y = x `rem` y == 0 | |
showInt :: Int -> String | |
showInt x | x `divisible` 15 = "FizzBuzz" | |
| x `divisible` 3 = "Fizz" | |
| x `divisible` 5 = "Buzz" | |
| otherwise = show x | |
fizzbuzz :: [String] | |
fizzbuzz = [showInt x | x <- [1..100]] | |
main = mapM_ putStrLn 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
class FizzBuzz { | |
public static void main(String[] args) { | |
for(int i = 0; i <= 100; i++) { | |
if(i % 15 == 0) { | |
System.out.println("FizzBuzz"); | |
} | |
else if(i % 3 == 0) { | |
System.out.println("Fizz"); | |
} | |
else if(i % 5 == 0) { | |
System.out.println("Buzz"); | |
} | |
else { | |
System.out.println(i); | |
} | |
} | |
} | |
} |
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
(loop for i from 1 to 100 do | |
(cond | |
((and | |
(= (rem i 3) 0) | |
(= (rem i 5) 0)) | |
(format t "FizzBuzz~%")) | |
((= (rem i 3) 0) | |
(format t "Fizz~%")) | |
((= (rem i 5) 0) | |
(format t "Buzz~%")) | |
(T | |
(format t "~a~%" i)))) |
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
def divisible?(x, y) | |
x % y == 0 | |
end | |
def show_int(x) | |
if divisible? x, 15 | |
'FizzBuzz' | |
elsif divisible? x, 3 | |
'Fizz' | |
elsif divisible? x, 5 | |
'Buzz' | |
else | |
x.to_s | |
end | |
end | |
(1..100).each do |x| | |
puts show_int x | |
end |
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
fn main() { | |
for n in range(1, 101) { | |
println( | |
if n % 15 == 0 { | |
~"FizzBuzz" | |
} else if n % 3 == 0 { | |
~"Fizz" | |
} else if n % 5 == 0 { | |
~"Buzz" | |
} else { | |
n.to_str() | |
} | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment