Skip to content

Conway's Game of Life in an many programming languages as I can figure out

License

Notifications You must be signed in to change notification settings

mrivnak/game-of-life

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Conway's Game of Life

Introduction

Conway's Game of Life in an many programming languages as I can figure out

Ada Bash C C++ C# COBOL Cython D Dart Fortran F# Go Haskell Java Julia Lua Nim OCaml Perl PHP PowerShell Python Ruby Rust TypeScript V Visual Basic Zig

The games are all setup to run a 100x50 (WxH) board for 500 generations. Most of them were originally written to be dynamic and find the terminal size or accept arguments but it was taking too much work to get all of that set up for each language and (imo) distracting from the purpose of this by shifting half of the work onto random argument parsing libraries rather than the languages themselves.

Contents

Prerequisites

  • Ada 95
    • GCC Gnat
    • GCC Gnatmake
  • Bash
  • C
    • GCC
    • GNU Make
  • C++
    • GCC
    • Meson
    • Ninja
  • C#
    • .NET 7.0 SDK
  • COBOL
    • GnuCOBOL
  • Cython
    • Python headers
  • D
    • GCC GDC
  • Dart
  • Fortran
    • GCC GFortran
  • F#
    • .NET 7.0 SDK
  • Go
  • Haskell
    • GHC
  • Java
    • Gradle
  • Julia
  • Lua
  • Nim
  • OCaml
    • OCaml
    • OPAM
    • Dune
  • Perl
  • PHP 7+
  • PowerShell
  • Python
  • Ruby
  • Rust
    • Cargo
  • Typescript
    • Node.js
    • Yarn
  • V
  • Visual Basic
    • .NET 7.0 SDK
  • Zig

Build from Source

Ada

cd ada/
gnatmake src/game_of_life.adb
./game_of_life

Bash

cd bash/
./game_of_life.sh

C

cd c/
make
./game_of_life

C++

cd cpp/
meson setup build
cd build
ninja
./game_of_life

C#

cd csharp/
dotnet run

Cobol

cd cobol/
make
./game_of_life

Cython

cd cython/
python setup.py build_ext --inplace
python main.py

D

cd d/
make
./game_of_life

Dart

cd dart/
dart run

Fortran

cd fortran/
make
./game_of_life

F#

cd fsharp/
dotnet run

Go

cd go/
go run .

Haskell

cd haskell/
ghc -o game_of_life main.hs game.hs board.hs
./game_of_life

Java

cd java/
./gradlew run --console plain

Julia

cd julia/
julia game_of_life.jl

Lua

cd lua/
lua game_of_life.lua

Nim

cd nim/
nim c -r GameOfLife.nim

OCaml

cd ocaml/
dune build
./_build/default/bin/main.exe

Perl

cd perl/
perl GameOfLife.pl

PHP

cd php/
php gameoflife.php

PowerShell

cd powershell/
pwsh Game-Of-Life.ps1

Python

cd python/
python game_of_life.py

Ruby

cd ruby/
ruby GameOfLife.rb

Rust

cd rust/
cargo run

Typescript

cd typescript/
yarn install
yarn run start

V

cd v/
v run .

Visual Basic

cd vb/
dotnet run

Zig

cd zig/
zig build run

Benchmarking

There's an included script to build all version and run benchmarks. It requires hyperfine to run

python benchmark.py

--install is only needed on the first run to install the script's dependencies

You can also specify how many iterations to run the benchmark (default 5), averaging the results

python benchmark.py --iterations 5

The set of languages to run in the benchmark can also be set. NOTE: Some languages, e.g. bash, powershell, are disabled by default for performance reasons. The default set is "ada,c,cpp,csharp,cobol,d,dart,fortran,fsharp,go,haskell,java,julia,lua,nim,perl,python,ruby,rust,typescript,vb,zig"

python benchmark.py --languages c,cpp,rust
# or
python benchmark.py --languages all

Container Build

podman build -t game-of-life .

podman run --rm game-of-life
# or
podman run --rm game-of-life "python benchmark.py --iterations 5 --languages c,cpp,rust"

NOTE: Docker will also work

Prebuilt Container

Container build

There's a prebuilt image on GitHub Container Registry since the container build is quite long, especially on low powered systems. Images will be available for x86_64 only.

podman pull ghcr.io/mrivnak/game-of-life:main
podman run --rm mrivnak/game-of-life:main

Dev Container

Visual Studio Code

Provided is a devcontainer.json file that will automatically setup a development environment for all of the languages in here, along with relevant extensions and language servers.