Skip to main content
6-Contributor
September 23, 2022
Solved

Create new vector based on element pairs of another vector

  • September 23, 2022
  • 1 reply
  • 1039 views

I have a vector [A], which can have any number of even rows and will contain only zeros or ones in each element. I would then like to create another vector [B], which will always have one more than half the number of rows in [A]. The top row element of [B] is always 1, and the following elements depend on the corresponding pairs of elements in [A], working from top to bottom. The element of [B] should be zero only if both the corresponding two elements of [A] are zero, otherwise it should be one. Something like this for a 4 row [A] and 3 row [B]:

Gaz_Ball_0-1663922674898.png

Gaz_Ball_1-1663922712973.png

Gaz_Ball_2-1663922738004.png

Gaz_Ball_3-1663922777475.png

Gaz_Ball_4-1663922799327.png

 

And for a 6 row [A] and 4 row [B]:

Gaz_Ball_0-1663924279543.png

 

Hopefully someone can help me out!
Thanks.

Best answer by LucMeekes

Here's a possible implementation of your function:

LucMeekes_0-1663927302351.png

Result(s):

LucMeekes_2-1663927357556.png

LucMeekes_1-1663927331554.png

If you cannot read the attached file, you must state which version of Prime you are using.

 

Success!
Luc

 

1 reply

LucMeekes23-Emerald IVAnswer
23-Emerald IV
September 23, 2022

Here's a possible implementation of your function:

LucMeekes_0-1663927302351.png

Result(s):

LucMeekes_2-1663927357556.png

LucMeekes_1-1663927331554.png

If you cannot read the attached file, you must state which version of Prime you are using.

 

Success!
Luc

 

Gaz_Ball6-ContributorAuthor
6-Contributor
September 23, 2022

Thanks Luc, that's great!