Back
Close

Resultant Vector Magnitude

Statement

 Goal

The resultant vector of two or more vectors originating from the same location is simply the sum of the components of the vectors also originating from the same point. This can also be referred to as vector addition.

In this puzzle you must sum the i, j , and k components of each 3-dimensional vector to create the resultant vector, and from there you must calculate the magnitude of the resultant vector using a derivation of the Pythagorean Theorem which is the square-root of the sum of the components squared.

√(i² + j² + k²)

The result is to be an integer expression of the magnitude such that any decimal values are truncated after the calculation.
Input
Line 1: An integer N for the number of vectors.
NextN lines: A string containing the i, j, k components represented with integers ranging from -100 to 100. The integer precedes the component label.
Output
Line 1: A string of the resultant vector formatted in a similar manner to the input vectors.
Line 2: The integer representation of the magnitude of the resultant vector.
Constraints
-100 <= i <= 100
-100 <= j <= 100
-100 <= k <= 100
Example
Input
2
1i 1j 1k
1i 1j 1k
Output
2i 2j 2k
3

Game modes
Fastest, Shortest

Test cases
2 Vectors Test
Input
2 1i 1j 1k 1i 1j 1k
Output
2i 2j 2k 3

2 Vectors Validator Validator
Input
2 2i 2j 2k 2i 2j 2k
Output
4i 4j 4k 6

1 Vector Test
Input
1 5i 3j 10k
Output
5i 3j 10k 11

1 Vector Validator Validator
Input
1 7i 9j 0k
Output
7i 9j 0k 11

Negative Components Test
Input
3 -3i -8j -15k -14i 4j -25k 8i 12j 55k
Output
-9i 8j 15k 19

Negative Components Validator Validator
Input
3 -6i 9j -2k 2i -77j 6k 0i 0j 0k
Output
-4i -68j 4k 68

Lots of Vectors Test
Input
13 5i 12j 1k -5i 0j 1k 5i -54j 1k -66i 32j -1k 7i -9j 0k 7i 12j 13k -25i -6j 44k -3i 0j -21k 0i -11j -7k 6i 45j -10k -8i 15j -2k 27i 11j -1k -41i -13j -9k
Output
-91i 34j 9k 97

Lots of Vectors Validator Validator
Input
13 4i 12j 1k -5i 0j 1k 5i -54j 1k -66i 32j -1k 7i -9j 0k 7i 12j 13k -25i -6j 44k -3i 0j -21k 0i -11j -7k 6i 45j -10k -8i 15j -2k 27i 11j -1k -41i -13j -9k
Output
-92i 34j 9k 98

Solution language

Solution

Stub generator input