Absolutely right! Using index is a good idea.
It is more convenient to use binary to store the sequence of numbers. Save a lot of push operators in unlock script.
Here is how to get an element by index from an array.
```
: get ( array index -- array element )
\ keep the origin array in altstack
over tas
\ [..., e, ...] -- [e, ...]
unit * split nip
\ [e, ...] -- e
unit split drop
\ reset origin array
fas swap
;
\ the byte size of the element in array
: unit 2 ;
: main
<<100:16, 101:16, 102:16, 103:16>> 2
get
<<102:16>>
equalverify
;
```
0064006500660067 OP_2 OP_OVER OP_TOALTSTACK OP_2 OP_MUL OP_SPLIT OP_NIP OP_2 OP_SPLIT OP_DROP OP_FROMALTSTACK OP_SWAP 0066 OP_EQUALVERIFY
Absolutely right! Using index is a good idea.
It is more convenient to use binary to store the sequence of numbers. Save a lot of push operators in unlock script.
Here is how to get an element by index from an array.
```
: get ( array index -- array element )
\ keep the origin array in altstack
over tas
\ [..., e, ...] -- [e, ...]
unit * split nip
\ [e, ...] -- e
unit split drop
\ reset origin array
fas swap
;
\ the byte size of the element in array
: unit 2 ;
: main
<<100:16, 101:16, 102:16, 103:16>> 2
get
<<102:16>>
equalverify
;
```
0064006500660067 OP_2 OP_OVER OP_TOALTSTACK OP_2 OP_MUL OP_SPLIT OP_NIP OP_2 OP_SPLIT OP_DROP OP_FROMALTSTACK OP_SWAP 0066 OP_EQUALVERIFY