#product #cartesian #terminal #cli

bin+lib product_index

Convert a cartesian product index into the N indicies of the original arrays

1 unstable release

0.1.0 Nov 17, 2023

#6 in #cartesian

MIT license

12KB
201 lines

product_index

A tool for get the ND indicies of a grid from a 1D index.

Usage

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]}"

Installation

To install from crates: cargo install product_index

To install manually, clone the repo and use cargo install --path .

Step by step Manual Install

  1. If cargo is not installed, install the rust compilers:
    curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
    
    (See https://www.rust-lang.org/tools/install for more options)
  2. Clone the repo:
    git clone https://github.com/chappertron/product_index.git
    
  3. cd into the repo folder
  4. Run the cargo install command:
    cargo install --path . 
    

You should now be able to access the product_index binary from the command line.

Dependencies

~1.2–1.9MB
~34K SLoC