Awesome
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:
- Using FizzBuzz to Find Developers who Grok Coding by Imran Ghory
- Why Can't Programmers.. Program? by Jeff Atwood
- The Problem with the FizzBuzz Problem by Gayle Laakmann McDowell
- FizzBuzz Still Works by Joey deVilla
- Further Into FizzBuzz! by Joey deVilla
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 (138 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 (111 of them) is:
- Ada
- Algol 60
- Algol 68
- Aribas
- Awk
- B
- BASIC (bwBASIC)
- Bash
- bc
- Bourne shell
- Bython
- C
- C#
- C++
- C-shell
- calc
- cat
- Clojure
- COBOL
- Common Lisp
- Crystal
- curl
- D
- Dart
- ed
- Elvish
- Emacs Lisp
- Erlang (using escript)
- Falcon
- Fish
- FizzBuzz
- Forth
- FORTRAN 66
- FORTRAN 77
- Fortran 90
- G-Portugol
- gcc error messages
- gdb
- Go
- Gravity
- Groovy
- Guile
- Haskell
- Haxe
- Hodor
- Icon
- Io
- Java
- JavaScript
- Julia
- Kotlin
- Lily
- Little
- Logo
- LOLCODE
- Lua
- M4
- Make
- Modula-2
- Myrddin
- Nickle
- Nim (formerly Nimrod)
- Node.js (JavaScript)
- NQP
- Objective-C
- Octave (should be compatible with Matlab)
- PARI/GP
- PHP
- Pascal
- Perl 5
- Perl 6
- PL/I
- PicoLisp
- Pike
- PostScript
- PowerShell
- Pure
- Python 2
- Python 3
- R
- Ratfor
- Rc (Plan 9 shell)
- REXX
- Ruby
- Rust
- S-Lang
- Scala
- sed
- Seed7
- SETL
- Simula
- Smalltalk
- SQLite3
- Squirrel
- Swift
- Tab
- tail
- Tcl
- Thompson Shell
- TypeScript
- V
- Vala
- Vigil
- Vimscript
- Visual Basic .NET
- Whitespace
- Wren
- x86/x86_64/SPARC assembly
- XPL
- Zig
- 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. All programs pass on Ubuntu 22.04.4 LTS.
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.