FizzBuzz is a nearly trivial programming exercise, sometimes used in job interviews to weed out candidates who say they can program but really can't.
References:
- [http://imranontech.com/2007/01/24/using-fizzbuzz-to-find-developers-who-grok-coding/](Using FizzBuzz to Find Developers who Grok Coding) by Imran Ghory
- [http://www.codinghorror.com/blog/2007/02/why-cant-programmers-program.html](Why Can't Programmers.. Program?) by Jeff Atwood
The requirements are simple:
Write a program that prints the numbers from 1 to 100. But for multiples of three print "Fizz" instead of the number and for the multiples of five print "Buzz". For numbers which are multiples of both three and five print "FizzBuzz".
In my fizzbuz-c project I present multiple (86 at last count) C solutions.
NOTE : This is not intended as a collaborative project. It is my own personal playground. A few people have submitted pull requests for languages I haven't covered, which I certainly appreciate, but I won't be accepting them. If you're interested in collaborating on something similar, see Rosetta Code. Bug reports are quite welcome.
Here I present multiple implementations, one in each language. The current set of languages (92 of them) is:
- Ada
- Algol 68
- Awk
- B
- BASIC (bwBASIC)
- Bash
- bc
- Bourne shell
- C
- C#
- C++
- C-shell
- cat
- Clojure
- COBOL
- Common Lisp
- Crystal
- curl
- D
- Dart
- Emacs Lisp
- Erlang (using escript)
- Falcon
- Fish
- FizzBuzz
- Forth
- FORTRAN 66
- FORTRAN 77
- Fortran 90
- G-Portugol
- gcc error messages
- gdb
- Go
- Groovy
- Guile
- Haskell
- Haxe
- Hodor
- Icon
- Io
- Java
- JavaScript
- Julia
- Lily
- Little
- Logo
- LOLCODE
- Lua
- M4
- Make
- Modula-2
- Myrddin
- Nim (formerly Nimrod)
- Node.js (JavaScript)
- NQP
- Objective-C
- Octave (should be compatible with Matlab)
- PHP
- Pascal
- Perl 5
- Perl 6
- Pike
- PostScript
- PowerShell
- Pure
- Python 2
- Python 3
- R
- Ratfor
- Rc (Plan 9 shell)
- REXX
- Ruby
- Rust
- Scala
- Seed7
- SETL
- Simula
- Smalltalk
- SQLite3
- Squirrel
- Swift
- Tab
- tail
- Tcl
- Thomson Shell
- Vala
- Vigil
- Vimscript
- Visual Basic .NET
- Whitespace
- x86/x86_64/SPARC assembly
- Zsh
Many of these are inspired by http://99-bottles-of-beer.net/.
tail
and cat
are simply the standard Unix/Linux utilities, not real
scripting languages. The cat
implementation in particular is an ugly
cheat, depending on the existence of the expected-output.txt
file.
JavaScript and Node.js aren't really distinct languages, but Node.js is a sufficiently different environment than plain JavaScript that I thought it was worth having both.
curl
is a URL transfer utility, not a programming language.
fizzbuzz.curl
, like fizzbuzz.cat
, depends on the existence
of expected-output.txt
, but on this GitHub
project
page rather
than in the current directory. It also requires an Internet connection.
The verify
script executes each program and confirms that its
output is correct. It works on my system, x86_64 Ubuntu 16.10,
with required packages installed as documented in each source file.
fizzbuzz.b
is not tested with an actual B compiler; see that file
for details.
fizzbuzz.sh6
failed due to a problem with the external goto
command.
I'm in touch with the maintainer to (I hope) get a fix for this. See
the sh6-bug
subdirectory for details. (For now I've worked around
this problem by using osh
rather than sh6
. osh
is an enhanced
implementation of sh6
that has goto
as a built-in command.)
The Whitespace web page is currently down, so I'm using the Perl implementation from here. I'll update the "comments" in the source file later (that's difficult to do, since I have to preserve existing whitespace).
I'm keeping an informal list of languages I intend to add in TODO.md.
Do not take this too seriously.