Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ken-matsui/diagonal-loop
Example code of diagonal loops for 2 & 3-dimensional arrays
https://github.com/ken-matsui/diagonal-loop
Last synced: about 1 month ago
JSON representation
Example code of diagonal loops for 2 & 3-dimensional arrays
- Host: GitHub
- URL: https://github.com/ken-matsui/diagonal-loop
- Owner: ken-matsui
- License: mit
- Created: 2023-03-04T02:49:27.000Z (almost 2 years ago)
- Default Branch: main
- Last Pushed: 2023-03-18T07:50:46.000Z (almost 2 years ago)
- Last Synced: 2024-10-16T13:17:50.929Z (3 months ago)
- Language: Rust
- Homepage:
- Size: 29.3 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# diagonal-loop
Example code of diagonal loops for 2 & 3-dimensional arrays
## Usage
```console
$ cargo run -- --help
Example code of diagonal loops for 2 & 3-dimensional arraysUsage: diagonal-loop [OPTIONS] [Z]
Arguments:
the length of x-axis
the length of y-axis
[Z] the length of z-axis (for a 3-dim array)Options:
-r, --report Show general information about diagonals
--no-elem Do not show elements
--bottom-up Loop diagonals bottom-up (default: top-down)
--block Split by blocks (BLOCK*BLOCK)
-h, --help Print help
-V, --version Print version
```## Examples
### 2-dimensional array
#### Simple Case
```console
$ cargo run -- 3 4
=== two_dimensional_diagonal_loop ===|(0,0)|(0,1)|(0,2)|(0,3)|
|(1,0)|(1,1)|(1,2)|(1,3)|
|(2,0)|(2,1)|(2,2)|(2,3)|top-down:
|(0,0)|
|(0,1)|(1,0)|
|(0,2)|(1,1)|(2,0)|
|(0,3)|(1,2)|(2,1)|
|(1,3)|(2,2)|
|(2,3)|=== two_dimensional_diagonal_loop ===
```#### Bottom-up loop
```console
$ cargo run -- 3 4 --bottom-up
=== two_dimensional_diagonal_loop ===|(0,0)|(0,1)|(0,2)|(0,3)|
|(1,0)|(1,1)|(1,2)|(1,3)|
|(2,0)|(2,1)|(2,2)|(2,3)|bottom-up:
|(0,0)|
|(1,0)|(0,1)|
|(2,0)|(1,1)|(0,2)|
|(2,1)|(1,2)|(0,3)|
|(2,2)|(1,3)|
|(2,3)|=== two_dimensional_diagonal_loop ===
```#### Use blocks
```console
$ cargo run -- 4 4 --block 2
=== two_dimensional_diagonal_loop ===|(0,0)|(0,1)|(0,2)|(0,3)|
|(1,0)|(1,1)|(1,2)|(1,3)|
|(2,0)|(2,1)|(2,2)|(2,3)|
|(3,0)|(3,1)|(3,2)|(3,3)|top-down:
|(0,0)..=(1,1)|
|(0,2)..=(1,3)|(2,0)..=(3,1)|
|(2,2)..=(3,3)|
|=== two_dimensional_diagonal_loop ===
```#### With `--report`
```console
$ cargo run -- 3 4 --report
=== two_dimensional_diagonal_loop ===|(0,0)|(0,1)|(0,2)|(0,3)|
|(1,0)|(1,1)|(1,2)|(1,3)|
|(2,0)|(2,1)|(2,2)|(2,3)|top-down:
|(0,0)|
|(0,1)|(1,0)|
|(0,2)|(1,1)|(2,0)|
|(0,3)|(1,2)|(2,1)|
|(1,3)|(2,2)|
|(2,3)|=== Report ===
num of diagonals: 6
max diagonal len (middle): 3
ave diagonal len: 2.00=== two_dimensional_diagonal_loop ===
```#### With `--no-elem`
```console
$ cargo run -- 123 283 --report --no-elem
=== two_dimensional_diagonal_loop ====== Report ===
num of diagonals: 405
max diagonal len (middle): 123
ave diagonal len: 85.95=== two_dimensional_diagonal_loop ===
```### 3-dimensional array
#### Simple Case
```console
$ cargo run -- 3 3 3
=== three_dimensional_diagonal_loop ===z = 0
|(0,0,0)|(0,1,0)|(0,2,0)|
|(1,0,0)|(1,1,0)|(1,2,0)|
|(2,0,0)|(2,1,0)|(2,2,0)|z = 1
|(0,0,1)|(0,1,1)|(0,2,1)|
|(1,0,1)|(1,1,1)|(1,2,1)|
|(2,0,1)|(2,1,1)|(2,2,1)|z = 2
|(0,0,2)|(0,1,2)|(0,2,2)|
|(1,0,2)|(1,1,2)|(1,2,2)|
|(2,0,2)|(2,1,2)|(2,2,2)|top-down:
|(0,0,0)|
|(0,0,1)|(0,1,0)|(1,0,0)|
|(0,0,2)|(0,1,1)|(0,2,0)|(1,0,1)|(1,1,0)|(2,0,0)|
|(0,1,2)|(0,2,1)|(1,0,2)|(1,1,1)|(1,2,0)|(2,0,1)|(2,1,0)|
|(0,2,2)|(1,1,2)|(1,2,1)|(2,0,2)|(2,1,1)|(2,2,0)|
|(1,2,2)|(2,1,2)|(2,2,1)|
|(2,2,2)|=== three_dimensional_diagonal_loop ===
```#### Bottom-up loop
```console
$ cargo run -- 3 3 3 --bottom-up
=== three_dimensional_diagonal_loop ===z = 0
|(0,0,0)|(0,1,0)|(0,2,0)|
|(1,0,0)|(1,1,0)|(1,2,0)|
|(2,0,0)|(2,1,0)|(2,2,0)|z = 1
|(0,0,1)|(0,1,1)|(0,2,1)|
|(1,0,1)|(1,1,1)|(1,2,1)|
|(2,0,1)|(2,1,1)|(2,2,1)|z = 2
|(0,0,2)|(0,1,2)|(0,2,2)|
|(1,0,2)|(1,1,2)|(1,2,2)|
|(2,0,2)|(2,1,2)|(2,2,2)|bottom-up:
|(0,0,0)|
|(1,0,0)|(0,1,0)|(0,0,1)|
|(2,0,0)|(1,1,0)|(0,2,0)|(1,0,1)|(0,1,1)|(0,0,2)|
|(2,1,0)|(1,2,0)|(2,0,1)|(1,1,1)|(0,2,1)|(1,0,2)|(0,1,2)|
|(2,2,0)|(2,1,1)|(1,2,1)|(2,0,2)|(1,1,2)|(0,2,2)|
|(2,2,1)|(2,1,2)|(1,2,2)|
|(2,2,2)|=== three_dimensional_diagonal_loop ===
```#### With `--report`
```console
$ cargo run -- 3 3 3 --report
=== three_dimensional_diagonal_loop ===z = 0
|(0,0,0)|(0,1,0)|(0,2,0)|
|(1,0,0)|(1,1,0)|(1,2,0)|
|(2,0,0)|(2,1,0)|(2,2,0)|z = 1
|(0,0,1)|(0,1,1)|(0,2,1)|
|(1,0,1)|(1,1,1)|(1,2,1)|
|(2,0,1)|(2,1,1)|(2,2,1)|z = 2
|(0,0,2)|(0,1,2)|(0,2,2)|
|(1,0,2)|(1,1,2)|(1,2,2)|
|(2,0,2)|(2,1,2)|(2,2,2)|top-down:
|(0,0,0)|
|(0,0,1)|(0,1,0)|(1,0,0)|
|(0,0,2)|(0,1,1)|(0,2,0)|(1,0,1)|(1,1,0)|(2,0,0)|
|(0,1,2)|(0,2,1)|(1,0,2)|(1,1,1)|(1,2,0)|(2,0,1)|(2,1,0)|
|(0,2,2)|(1,1,2)|(1,2,1)|(2,0,2)|(2,1,1)|(2,2,0)|
|(1,2,2)|(2,1,2)|(2,2,1)|
|(2,2,2)|=== Report ===
num of diagonals: 7
max diagonal len (middle): 7
ave diagonal len: 3.86=== three_dimensional_diagonal_loop ===
```#### With `--no-elem`
```console
$ cargo run -- 123 283 326 --report --no-elem
=== three_dimensional_diagonal_loop ====== Report ===
num of diagonals: 730
max diagonal len (middle): 33209
ave diagonal len: 15544.84=== three_dimensional_diagonal_loop ===
```