Skip to content

Instantly share code, notes, and snippets.

@lancylot2004
Last active December 3, 2023 00:46
Show Gist options
  • Save lancylot2004/a1e3570e49fe92d197c4d36d1ba80c9e to your computer and use it in GitHub Desktop.
Save lancylot2004/a1e3570e49fe92d197c4d36d1ba80c9e to your computer and use it in GitHub Desktop.
Fizzbuzz One-Liners
// == Rules ==
// 1. Goes from 1 to 100, inclusive.
// 2. Must print everything to console (or as close to as possible).
// 3. (Obviously) must be one line, type signatures and other inherent restrictions aside.
// 4. Makes sense, and extensible. Shouldn't take much effort to add "bonk"!
// 5. Forget neat code - going for shortest!
// Haskell
main :: IO (); main = mapM_ putStrLn [max(show x)$concat$["fizz"|x`mod`3==0]++["buzz"|x`mod`5==0]|x<-[1..100]]
// JavaScript, @alexanderbira
for(let i=0;i<100;console.log((((!(++i%3)&&"fizz")||"")+((!(i%5)&&"buzz")||""))||i));
// Python
[print('fizz'*(i%3==0)+'buzz'*(i%5==0) or i) for i in range(1, 101)]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment