Note: This challenge has been changed to eliminate the strict whitespace manipulation requirements that made this challenge low-quality. Some rules regarding whitespace have been changed.
I'm rather good at mental math, particularly adding positive integers in my head. Here is my method for adding the numbers together (n
is a positive integer):
- Arrange the numbers in a horizontal row
- Reorder the numbers so the
2n-1
th number in the sequence is then
th smallest number in the sequence and the2n
th number in the sequence is then
th largest number in the sequence. - Add the
2n-1
th number to the2n
th number. Print the results of these additions on the next line. - Repeat the previous step until a final result is obtained.
Your challenge is to write a program or function that prints each of the above steps until the sum of all the inputted numbers is reached. The final result must be separated from the adding steps by an additional blank newline. You may assume that all numbers inputted are unique so as to avoid confusion with the second step (and that the input is not empty). Numbers can be inputted in any format. Numbers in rows should be separated from each other by one space.
Test cases
For each of these, the input and output start a newline after their labels.
Case 1
Input:
314 495 767 214 141
Output:
141 767 214 495 314 //Reordering the input
908 709 314 //Adding
1617 314
1931 //Final result
Case 2
Input:
884
Output:
884 //Reordering the input
884 //Final result
Note that there is no adding step here because the reordering of the input produces the final result.
Case 3
Input:
5033 7825 2167 6374 5050 5389 3915 7231 3025 1954 7249 5143 7567 9857 462 3504 6165 6681 6361 6367
Output:
462 9857 1954 7825 2167 7567 3025 7249 3504 7231 3915 6681 5033 6374 5050 6367 5143 6361 5389 6165
10319 9779 9734 10274 10735 10596 11407 11417 11504 11554
20098 20008 21331 22824 23058
40106 44155 23058
84261 23058
107769
This is code golf. Standard rules apply. Answer with the fewest bytes wins.