FizzBuzz in different languages, just for fun.
Last active
June 10, 2023 17:12
-
-
Save yuigoto/64f16a9ccc48c133c845e46554d12857 to your computer and use it in GitHub Desktop.
FizzBuzz in different languages, just out of curiosity
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
main() { | |
for (int c = 0; c < 100; c++) { | |
int d = c + 1; | |
if (d % 3 == 0 && d % 5 == 0) { | |
print("FizzBuzzz"); | |
} else if (d % 3 == 0) { | |
print("Fizz"); | |
} else if (d % 5 == 0) { | |
print("Buzz"); | |
} else { | |
print(d); | |
} | |
} | |
} |
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 | |
func main() { | |
for i := 0; i < 100; i++ { | |
curr := i + 1 | |
if curr%3 == 0 && curr%5 == 0 { | |
println("FizzBuzz") | |
} else if curr%3 == 0 { | |
println("Fizz") | |
} else if curr%5 == 0 { | |
println("Buzz") | |
} else { | |
println(curr) | |
} | |
} | |
} |
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 { | |
static function main() { | |
var n: Int = 0; | |
for (i in 0...100) { | |
var c: Int = i + 1; | |
if (c % 3 == 0 && c % 5 == 0) { | |
trace("FizzBuzz"); | |
} else if (c % 3 == 0) { | |
trace("Fizz"); | |
} else if (c % 5 == 0) { | |
trace("Buzz"); | |
} else { | |
trace(c); | |
} | |
} | |
} | |
} |
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 Main { | |
public static void main(String[] args) { | |
int n = 0; | |
for (int l = 0; l < 100; l++) { | |
int c = l + 1; | |
if (c % 3 == 0 && c % 5 == 0) { | |
System.out.println("FizzBuzz"); | |
} else if (c % 3 == 0) { | |
System.out.println("Fizz"); | |
} else if (c % 5 == 0) { | |
System.out.println("Buzz"); | |
} else { | |
System.out.println(c); | |
} | |
} | |
} | |
} |
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
// Compact | |
for(x=[],i=1;i<=100;x.push((i%3 && i%5)?i:((i%3)?"":"Fizz")+((i%5)?"":"Buzz")),i++);console.log(x); | |
// Expanded | |
var x = []; | |
for ( i = 1; i <= 100; i++ ) { | |
if ( i % 3 && i % 5 ) { | |
x.push( i ); | |
} else { | |
var n = ""; | |
if ( i % 3 == 0 ) n += "Fizz"; | |
if ( i % 5 == 0 ) n += "Buzz"; | |
x.push( n ); | |
} | |
} | |
// A bit more compact? | |
for(var i=1;i<=100;console.log(((i%3 && i%5)?i:((i%3)?"":"Fizz")+((i%5)?"":"Buzz"))+"\r\n"),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
for i=1,100,1 | |
do | |
if(i%3==0 or i%5==0)then | |
z='' | |
if (i%3==0) then z = z.."Fizz" end | |
if (i%5==0) then z = z.."Buzz" end | |
print(z) | |
else | |
print(i) | |
end | |
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
var n = 0; | |
for n in 1..100: | |
if n mod 3 == 0 and n mod 5 == 0: | |
echo "FizzBuzz" | |
elif n mod 3 == 0: | |
echo "Fizz" | |
elif n mod 5 == 0: | |
echo "Buzz" | |
else: | |
echo n |
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
for(int i=1;i<=100;i++){ | |
if(i%3==0||i%5==0){ | |
if(i%3==0) print("Fizz"); | |
if(i%5==0) print("Buzz"); | |
println(""); | |
} else { | |
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
<?php | |
for ($n = 0; $n < 100; $n++) { | |
$l = $n + 1; | |
if ($l % 3 === 0 && $l % 5 === 0) { | |
echo "fizzbuzz"; | |
} elseif ($l % 3 === 0) { | |
echo "fizz"; | |
} elseif ($l % 5 === 0) { | |
echo "fizz"; | |
} else { | |
echo $l; | |
} | |
echo "\n"; | |
} |
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
a = ""; | |
for i in range(101): # xrange in python 2 | |
if i == 0: | |
continue | |
elif ( i%3==0 or i%5==0 ): | |
x = ""; | |
if ( i%3==0 ): x += "Fizz" | |
if ( i%5==0 ): x += "Buzz" | |
# print(x) | |
a += x + ", " | |
else: | |
a += str(i) + ", " | |
# print(i) | |
print(a) |
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
x = Array.new | |
# ".." is <=, "..." is < | |
for i in 1..100 | |
if(i%3==0||i%5==0) | |
z = ""; | |
if (i%3==0) then z += "Fizz" end | |
if (i%5==0) then z += "Buzz" end | |
puts z + ": #{i}" | |
else | |
puts i | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment