#doors #ncurses #cli #math-problem

app hundred-doors

A tool for calculating and visualizing the '100 Doors' problem

4 releases

0.1.3 Feb 4, 2024
0.1.2 Jan 26, 2024
0.1.1 Jan 25, 2024
0.1.0 Jan 25, 2024

#202 in Math

26 downloads per month

GPL-3.0 license

6KB
70 lines

100 Doors

Imagine a hundred closed doors in a corridor. You go and open every one of them. Then, you open every second one. (If the door was open, then just close it.) Then, every third. Then, every fourth and every fifth and so on until you only touch the 100th door. How many doors are open now?

This is a mathematical problem known as "100 Doors". I have written a smol program in Rust that calculates and visualizes the solution using ncurses-rs.

A simple program that calculates and visualizes the "100 Doors" problem

Usage: hundred-doors [OPTIONS] [NUMBER]

Arguments:
  [NUMBER]  How many doors there are [default: 100]

Options:
  -d, --draw           Whether there should be a graphical representation of these doors
  -e, --explain        Whether to explain the problem
      --twave <TWAVE>  How many milliseconds to wait before the next wave [default: 0]
      --tdoor <TDOOR>  How many milliseconds to wait between new doors [default: 0]
  -h, --help           Print help
  -V, --version        Print version

Examples

$ hundred-doors 100
> 10
$ hundred-doors 100 --draw --tdoor 10 --twave 50

You'll see an "animation" of the respective doors. Here's a screenshot:

hundred-doors-screenshot

Dependencies

~1.3–2MB
~41K SLoC