Typically, when we want to represent a magnitude and direction in 2D space, we use a 2-axis vector. These axes are typically called X and Y:
This isn't always convenient, however. The game BattleTech is played on a hexagonal grid, and it's convenient for the axes to line up with the sides of the hexagons. To represent velocity, thrust, and other such values, BattleTech uses a 6-axis Thrust Vector, with axes named A-F:
Here are a few example Thrust Vectors, all of which represent the following magnitude and direction:
{ A = 2, B = 1, C = 0, D = 0, E = 0, F = 0 }
{ A = 3, B = 0, C = 1, D = 0, E = 0, F = 0 }
{ A = 5, B = 0, C = 0, D = 3, E = -1, F = 0 }
This follows from two rules of equivalence for Thrust Vectors:
- Adding or subtracting the same value to two opposite axes (A/D, B/E or C/F) leads to an equivalent Thrust Vector:
{ A = 1, D = 1 }
=>{A = 0, D = 0}
- Subtracting a value from two axes with a single axis between them (A/C, B/D, C/E, D/F, E/A, F/B) and adding that value to the axis between them leads to an equivalent Thrust Vector:
{ A = 1, B = 0, C = 1 }
=>{ A = 0, B = 1, C = 0}
It is possible to make a simple Thrust Vector look very complicated by placing value in axes in a different direction than the vector actually points in, which is undesirable. A Consolidated Thrust Vector is a Thrust Vector that fulfills the following conditions:
- No axes hold a negative value.
- There are up to 2 axes with nonzero values.
- If there are 2 axes with nonzero values, they are adjacent axes.
Of the above example vectors, only the first is Consolidated.
Your challenge is to accept a 6-axis vector (as a 6-element list or other convenient structure) of integer magnitudes, and return an equivalent vector which has been consolidated. There is only one possible solution for any given input.
Test cases:
-1, 0, 0, 0, 0, 0
=>0, 0, 0, 1, 0, 0
1, 0, 0, 2, 0, 0
=>0, 0, 0, 1, 0, 0
1, 0, 2, 0, 0, 0
=>0, 1, 1, 0, 0, 0
1, 2, 3, 4, 5, 6
=>0, 0, 0, 0, 6, 0
1, 0, 2, 0, 3, 0
=>0, 0, 0, 1, 1, 0
1, 0, 1, 0, 1, 0
=>0, 0, 0, 0, 0, 0
0, 0, 0, 0, 0, 0
=>0, 0, 0, 0, 0, 0
0, 0, 0, 0, 0, 1
=>0, 0, 0, 0, 0, 1
1, 0, 0, 0, 1, 0
=>0, 0, 0, 0, 0, 1
-1, -1, -1, 1, 1, 1
=>0, 0, 0, 0, 4, 0