Input
4 integers w, x, y, z from the range -999 to 999 inclusive where none of the values is 0.
Output
4 integers a, b, c, d so that aw + bx + cy + dz == 0 where none of the values is 0.
Restrictions
Your output should be the solution with the smallest sum of absolute values possible. That is the smallest value of \$|a|+|b|+|c|+|d|\$. If there is more than one solution with the same sum of absolute values you can choose any one of them arbitrarily.
Examples
Input: 78 -75 24 33
Output: b = -1, d = 1, a = -2, c = 2
Input: 84 62 -52 -52
Output: a = -1, d = -1, b = -2, c = -3
Input: 26 45 -86 -4
Output: a = -3, b = -2, c = -2, d = 1
Input: 894 231 728 -106
Output: a = 3, b = -8, c = -1, d = 1
Input: -170 962 863 -803
Output: a = -5, d = 8, c = 2, b = 4
Added thanks to @Arnauld
Input: 3 14 62 74
Output: -2, 4, -2, 1
Unassessed bonus
Not in the challenge but does your code also work on this?
Input: 9923 -9187 9011 -9973
3 14 62 74
(you'll find[ -2, 3, 3, -3 ]
if you just try all values between-m
andm
and increasem
until a solution is found; but[ -2, 4, -2, 1 ]
is better). \$\endgroup\$