Last active
May 17, 2022 04:45
Star
You must be signed in to star a gist
Some Fizzbuzz for meditation
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
// This one is interesting because no previously checked condition is re-checked | |
// It is a self-executing function that contains a declarative function named fizzbuzz() and a for loop | |
// Too much fun | |
(function() { | |
function fizzbuzz(i) { | |
const test = (d, s, x) => i % d == 0 ? _ => s + x('') : x | |
const fizz = x => test(3, 'Fizz', x) | |
const buzz = x => test(5, 'Buzz', x) | |
console.log(fizz(buzz(x=>x))(i.toString())) | |
} | |
for (let i = 1; i <= 100; i += 1){ | |
fizzbuzz(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=0;i<100;)console.log((++i%3?'':'fizz')+(i%5?'':'buzz')||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
// Exceedingly fast approach | |
// Array is concatenated to a single newline separated string and output | |
Array.apply(0, Array(100)).map(function (_, i) { | |
i += 1 | |
const fizzes = i % 3 == 0 | |
const buzzes = i % 5 == 0 | |
const fizzBuzz = (fizzes && buzzes) | |
if (fizzBuzz) return 'FizzBuzz' | |
if (fizzes) return 'Fizz' | |
if (buzzes) return 'Buzz' | |
return i | |
}).join("\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
// This is a decent answer to the deceptively awesome interview question of fizzbuzz | |
for(i=0; i<=100;i++){ | |
let x='' | |
if (!(i%3)) x +='Fizz' | |
if (!(i%5)) x +='Buzz' | |
console.log( x || i.toString() ) | |
} |
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 | |
// no 'if' nor '%' operator, so there's that. | |
$step[0] = 3; | |
$step[1] = 5; | |
$step[2] = 15; | |
for ($i = 1; $i<=100; $i++) { | |
$x[$i] = $i; | |
} | |
for ($i = $step[0]; $i <= 100; $i = $i + $step[0]) { | |
$x[$i] = "Fizz"; | |
} | |
for ($i = $step[1]; $i <= 100; $i = $i + $step[1]) { | |
$x[$i] = "Buzz"; | |
} | |
for ($i = $step[2]; $i <= 100; $i = $i + $step[2]) { | |
$x[$i] = "FizzBuzz"; | |
} | |
echo(implode(PHP_EOL, array_values($x))); |
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 | |
// There are only 10 kinds of people in the world | |
// People who understand binary and people who don't | |
// And people who understand ternary | |
for($i=0;$i++<100;)echo($i%3?'':'Fizz').($i%5?'':'Buzz')?:$i,"\n"; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment