Crates.io | product_index |
lib.rs | product_index |
version | 0.1.0 |
source | src |
created_at | 2023-11-17 15:44:36.84393 |
updated_at | 2023-11-17 15:44:36.84393 |
description | Convert a cartesian product index into the N indicies of the original arrays |
homepage | https://github.com/chappertron/product_index |
repository | https://github.com/chappertron/product_index |
max_upload_size | |
id | 1039196 |
size | 19,628 |
product_index
A tool for get the ND indicies of a grid from a 1D index.
arr1=($(seq 1 1 5))
arr2=($(seq 1 1 6))
N=12
# prints 2 0
product_index $N "${#arr1[@]}" "${#arr2[@]}"
# stores i1=2 i2=0
read -r i1 i2 <<< $(product_index $N "${#arr1[@]}" "${#arr2[@]}")
# Prints 3,1
echo "x,y = ${arr1[$i1]}, ${arr2[$i2]}"
To install from crates:
cargo install product_index
To install manually, clone the repo and use cargo install --path .
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
(See https://www.rust-lang.org/tools/install for more options)git clone https://github.com/chappertron/product_index.git
cd
into the repo foldercargo install --path .
You should now be able to access the product_index
binary from the command line.