GithubHelp home page GithubHelp logo

your-diary / fizzbuzz_with_50_languages Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 222 KB

Implementations of the FizzBuzz game with 50+ programming languages.

License: Other

C 2.24% Shell 36.76% Go 6.54% Assembly 4.67% C++ 2.45% Fortran 3.55% D 2.38% Rust 3.05% Python 1.33% Ruby 4.95% Crystal 4.46% PHP 6.54% Lua 2.52% MoonScript 1.59% Perl 3.70% Raku 1.51% JavaScript 4.51% TypeScript 2.85% CoffeeScript 1.66% Dart 2.73%

fizzbuzz_with_50_languages's Introduction

FizzBuzz with 50+ Languages

1. About

In this project, we implement the FizzBuzz game with 50+ programming languages.

References

2. Contents

For each programming language, this project includes

  1. How to install the compiler or the interpreter for the language (see Setup Development Environments).

  2. How to use such tools (see Setup Development Environments).

  3. How to comment out string in the language (see the first line of the source code).

  4. How to implement the FizzBuzz game (see the source code). For a limited number of difficult languages (e.g. Assembly), we only implemented Hello World.

3. Assumptions

OS

Unless otherwise, we use Arch Linux.

Shell Environments

Hereafter, we define the function aur() as follows.

function aur() {
    if [[ $# == 0 || $1 == "-h" || $1 == "--help" ]]; then
        echo "Usage: aur <AUR package name>"
        return 0
    fi
    git clone "https://aur.archlinux.org/${1}.git"
}

And we execute the following command.

mkdir ~/Build

4. Usage

  1. Read Setup Development Environments and setup the development environment for the language.

  2. cd ./093_Some_Language

  3. bash yrun.sh

5. How to Add Languages

This section is for contributors of this project.

  1. mkdir 093_Some_Language

  2. cd 093_Some_Language

  3. cp ../yrun.sh .

  4. echo 'some_language_interpreter --run "${source}.some_extension"' >> yrun.sh (The variable source is by default defined as fizzbuzz in ../yrun_template.sh, which is sourced from yrun.sh. You do not have to define it.)

  5. Put the source code fizzbuzz.some_extension here.

  6. bash yrun.sh > x && vimdiff x ../correct_output.txt to check the result is correct.

  7. Confirm fizzbuzz.some_extension starts with a comment line (e.g. # This is a comment.).

6. Setup Development Environments

001. C

gcc <source>.c -o <source>.out
./<source>.out

Installation: sudo pacman -S gcc

002. Go

go run <source>.go

Installation: sudo pacman -S go

003. Assembly

nasm -felf64 <source>.asm
ld <source>.o -o <source>.out
./<source>.out

Installation: sudo pacman -S nasm

004. C++

g++ <source>.cpp -o <source>.out
./<source>.out

Installation: sudo pacman -S gcc

005. FORTRAN

gfortran <source>.f90 -o <source>.out
./<source>.out

Installation: sudo pacman -S gcc-fortran

006. D

dmd <source>.d -of=<source>.out
./<source>.out

Installation: sudo pacman -S dlang-dmd

007. Rust

rustc --allow unused_parens <source>.rs -o <source>.out
./<source>.out

Installation: sudo pacman -S rust

008. Python

python3 <source>.py

Installation: sudo pacman -S python

009. Ruby

ruby <source>.rb

Installation: sudo pacman -S ruby

010. Crystal

crystal <source>.cr

Installation: sudo pacman -S crystal

011. PHP

php <source>.php

Installation: sudo pacman -S php

Additional Notes

You can embed PHP codes into HTML and serve it by parsing the PHP part server-side. For Apache, read Apache HTTP Server - ArchWiki and open ./011_PHP_02.php.

012. Lua

lua <source>.lua

Installation: sudo pacman -S lua

013. MoonScript

Only a compiler for Windows is supplied. However, you can use the official online compiler: MoonScript Online Compiler

014. Perl

perl <script>.pl

Installation: sudo pacman -S perl

015. Raku (Perl 6)

rakudo <source>.p6

Installation

cd ~/Build
aur moarvm
cd moarvm/
makepkg -sir

cd ~/Build
aur nqp
cd nqp/
makepkg -sir

cd ~/Build
aur rakudo
cd rakudo/
makepkg -sir

016. JavaScript

node <source>.js

Installation: sudo pacman -S nodejs

017. TypeScript

tsc <source>.ts
node <source>.js

Installation: sudo pacman -S typescript

018. CoffeeScript

coffee <source>.coffee

Installation: sudo pacman -S coffeescript

019. Dart

dart <source>.dart

Installation: sudo pacman -S dart

020. WebAssembly

/usr/lib/emscripten/emcc <source>.cpp -s WASM=1 -o <source>.html

This command outputs <source>.html, <source>.js and <source>.wasm. They shall be served via a HTTP server. See Compiling a New C/C++ Module to WebAssembly - MDN for the detail.

Installation: sudo pacman -S emscripten

021. Java

/usr/lib/jvm/java-14-openjdk/bin/javac <source>.java
/usr/lib/jvm/java-14-openjdk/bin/java <source>

Installation: sudo pacman -S jdk-openjdk

022. Vim script

vim -c 'source <source>.exscript'

Installation: sudo pacman -S gvim

023. Kotlin

kotlinc <source>.kt
kotlin _<source>

Installation: sudo pacman -S kotlin

024. Scala

scala <source>.scala

Installation: sudo pacman -S scala

025. Groovy

export JAVA_HOME=/usr/lib/jvm/java-14-openjdk
groovy <source>.groovy

Installation: sudo pacman -S groovy

026. Processing

cd <source> #The source code `<source>.pde` shall exist here.
processing-java --sketch="${PWD}" --run

Installation: sudo pacman -S processing

027. Swift

swift <source>.swift

Installation

cd ~/Build
aur swift-bin
cd swift-bin/
makepkg -sir

028. Objective-C

gcc -std=gnu11 -lgnustep-base -lobjc <source>.m -o <source>.out
./<source>.out

Installation: sudo pacman -S gcc-objc gnustep-base

029. C#

csc <source>.cs
chmod a+x <source>.exe
./<source>.exe

or

csc <source>.cs
mono <source>.exe

Installation: sudo pacman -S dotnet-sdk

030. F#

dotnet fsi <source>.fsx

Installation: sudo pacman -S dotnet-sdk

031. Visual Basic

vbc <source>.vb
chmod a+x <source>.exe
./<source>.exe

or

csc <source>.vb
mono <source>.exe

Installation

sudo pacman -S dotnet-sdk

cd ~/Build
aur mono-basic
cd mono-basic/
makepkg -sir

032. VBA (Visual Basic for Applications)

In this section, we assume you are using Windows and Excel 2016.

  1. Open Excel.

  2. View > Macros > View Macros

  3. Type a macro name you want.

  4. Click Create.

  5. Write your code.

  6. Type F5.

  7. Click Run.

033. GAS (Google Apps Script)

mkdir <project directory>
cd <project directory>
clasp create --type standalone --title <project title>
vi <source>.js
clasp push
script_id=$(sed 's/.*:"//; s/"}//' .clasp.json)
firefox "https://script.google.com/d/${script_id}/edit"
#Click `Run` or type `Ctrl+r` to run the script.
#Click `View` and `Logs` or type `Ctrl+Enter` to view the output.

Although you can run the script from the command-line via clasp run [<function name>], the preparations for the command to work are quite complex. See run.md - google/clasp for the detail.

Installation

npm install --global @google/clasp

#Visit https://script.google.com/home/usersettings and enable the Apps Script API.

clasp login

034. Object Pascal (Delphi)

fpc -Mdelphi <source>.pas
./<source>

Installation: sudo pacman -S fpc

035. Pascal

fpc <source>.pas
./<source>

Installation: sudo pacman -S fpc

036. ALGOL

a68g <source>.a68

Installation: sudo pacman -S algol68g

037. Ada

gnatmake <source>.adb
./<source>

Installation: sudo pacman -S gcc-ada

038. Wolfram Language

wolfram -script <source>.m

Installation: Consult the official instructions. You can display the activation key in https://user.wolfram.com/portal/myProducts.html.

039. AWK

awk -f <source>.awk

Installation: sudo pacman -S gawk

040. sed

sed --file=<source>.sed

Installation: sudo pacman -S sed

041. PowerShell

/opt/microsoft/powershell/7/pwsh <source>.ps1

Installation

cd ~/Build
aur powershell
cd powershell/
makepkg -sir

042. Command Prompt

#Open `cmd.exe` in Windows.

start <source>.bat

043. Bash

bash <source>.sh

Installation: sudo pacman -S bash

044. AppleScript

#Open `Terminal` in macOS.

osascript <source>.applescript

Installation: Pre-installed.

045. Haskell

ghc -dynamic <source>.hs
./<source>

or

runhaskell <source>.hs

Installation: sudo pacman -S ghc

046. OCaml

ocaml <source>.ml

Installation: sudo pacman -S ocaml

047. Standard ML

smlnj < <source>.sml

Installation: sudo pacman -S smlnj

048. Erlang

erlc <source>.erl
erl -noshell -s <source> <function name> -s init stop

Installation: sudo pacman -S erlang

049. Elixir

elixir <source>.exs

Installation: sudo pacman -S elixir

050. Common Lisp

clisp <source>.lisp

Installation: sudo pacman -S clisp

051. Clojure

clojure <source>.clj

Installation: sudo pacman -S clojure

052. Scheme

scheme --batch-mode < <source>.scm

Installation: sudo pacman -S mit-scheme

053. Prolog

echo | gprolog --consult-file "${source}.prolog" --query-goal <query command>

Installation: sudo pacman -S gprolog

054. Smalltalk

gst <source>.st

Installation: sudo pacman -S smalltalk

055. BASIC

fbc -lang deprecated <source>.bas
./<source>

Installation: sudo pacman -S freebasic

056. COBOL

cobc -x <source>.cobol
./<source>

Installation: sudo pacman -S gnucobol

057. Nadesiko

cnako3 <source>.nako3

Installation: npm install --global nadesiko3

058. HSP (Hot Soup Processor)

hspcmp <source>.hsp
hsp3cl <source>.ax

Installation

#Hereafter we use Ubuntu because
#1. Only debian-based distributions are officially supported.
#2. With newer `gcc`, `make` fails since the C++ source codes are written badly.
#   See |https://github.com/onitama/OpenHSP/issues/12| for the detail.
#   Of course, Arch Linux uses the latest `gcc` by default, which is problematic in this case.
docker run -it ubuntu

set -o vi

apt update
apt install gcc git make vim

git clone "https://github.com/onitama/OpenHSP"
cd OpenHSP/
sed -i 's/sudo //g' setup.sh
./setup.sh

059. R

R --no-echo --file=<source>.r

Installation: sudo pacman -S r

060. Julia

julia <source>.jl

Installation: sudo pacman -S julia

061. Octave

octave <source>.m

Installation: sudo pacman -S octave

062. Haxe

haxe --run <source>.hx

Installation: sudo pacman -S haxe

063. Nim

nim compile --run <source>.nim

or

nim compile <source>.nim
./<source>

Installation: sudo pacman -S nim

064. Brainfuck

bfc <source>.brainf
mv 'a.out' <source>.out
./<source>.out

Installation

cd ~/Build
aur brainfuck
cd brainfuck
makepkg -sir

065. gnuplot

gnuplot <source>.gp

Installation: sudo pacman -S gnuplot

066. bc

bc <source>.bc

Installation: sudo pacman -S bc

fizzbuzz_with_50_languages's People

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.