4个版本
0.1.3 | 2024年2月4日 |
---|---|
0.1.2 | 2024年1月26日 |
0.1.1 | 2024年1月25日 |
0.1.0 | 2024年1月25日 |
#347 in 数学
33 每月下载次数
6KB
70 行
百门问题
想象一条走廊里有100扇关闭的门。你去打开每一扇门。然后,打开每第二扇门。(如果门是开着的,就只是关上它。)然后,每第三扇。然后,每第四扇和每第五扇,以此类推,直到你只触摸到第100扇门。现在有多少扇门是开着的?
这是一个被称为“百门问题”的数学问题。我已经用Rust编写了一个小程序,使用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
示例
$ hundred-doors 100
> 10
$ hundred-doors 100 --draw --tdoor 10 --twave 50
你会看到一个对应门的“动画”。这是一张截图
依赖项
~1.3–2MB
~41K SLoC