amscotti/prisoners_rusty_riddle
wasi
Public
wasmer run amscotti/prisoners_rusty_riddle
wasmer run amscotti/prisoners_rusty_riddle
100 Prisoners Riddle Simulator
This application simulates many sessions of 100 Prisoners Riddle
Default strategy should return with 31% success rate with the steps of,
- Each prisoner first opens the drawer labeled with their own number.
- If this drawer contains their number, they are done and were successful.
- Otherwise, the drawer contains the number of another prisoner, and they next open the drawer labeled with this number.
- The prisoner repeats steps 2 and 3 until they find their own number, or fail because the number is not found in the first fifty opened drawers.
This is a strip down port of a Go version I created for I could experiment with Rust.
Resources
- 100 prisoners problem - Wikipedia
- The Riddle That Seems Impossible Even If You Know The Answer - YouTube
Build
Run cargo build --release to build
Usage
100 Prisoners Riddle Simulator
USAGE:
prisoners_rusty_riddle [OPTIONS]
OPTIONS:
-h, --help Print help information
-n, --number-of-sessions <NUMBER_OF_SESSIONS> Number of sessions to run [default: 10000000]
-V, --version Print version information
WebAssembly (wasm32-wasi) Experimenting
Using configuration conditional checks, this Application can be built for wasm32-wasi and will remove rayon dependency and related code.
To build for wasm32-wasi,
- Run
rustup target add wasm32-wasito add the target - Build with
cargo build --release --target=wasm32-wasi - and use wasmer to run, like so
wasmer target/wasm32-wasi/release/prisoners_rusty_riddle.wasm -- -n 1000000