25
2
Introduction
Arrays can also be seen as a field for a bouncing ball. This of course sounds very vague, so here is an example of an input:
[1, 2, 3, 4, 5, 6, 7, 8, 9]
[9, 8, 7, 6, 5, 4, 3, 2, 1]
[1, 2, 3, 4, 5, 6, 7, 8, 9]
The challenge is to output the bounced arrays. These are made from diagonal patterns which bounce at the edges of the field. This path is pointed upwards. The path for the first bounced array (in which the path is directly bounced off the egde), is:
[1, -, -, -, 5, -, -, -, 9]
[-, 8, -, 6, -, 4, -, 2, -]
[-, -, 3, -, -, -, 7, -, -]
From left to right, this would result in [1, 8, 3, 6, 5, 4, 7, 2, 9]
. This is our first bounced array. The path for the second bounced array:
[-, 2, -, -, -, 6, -, -, -]
[9, -, 7, -, 5, -, 3, -, 1]
[-, -, -, 4, -, -, -, 8, -]
This results in [9, 2, 7, 4, 5, 6, 3, 8, 1]
. The path for the third bounced array is:
[-, -, 3, -, -, -, 7, -, -]
[-, 8, -, 6, -, 4, -, 2, -]
[1, -, -, -, 5, -, -, -, 9]
This results in [1, 8, 3, 6, 5, 4, 7, 2, 9]
. So the three bounced arrays are:
[1, 8, 3, 6, 5, 4, 7, 2, 9]
[9, 2, 7, 4, 5, 6, 3, 8, 1]
[1, 8, 3, 6, 5, 4, 7, 2, 9]
Task
Given at least 1 array containing only non-negative integers, with all the arrays having the same length, output all the bounced arrays.
Test cases
Test case 1:
Input: Output:
[1, 2, 3, 4, 5] [1, 7, 3, 9, 5]
[6, 7, 8, 9, 0] [6, 2, 8, 4, 0]
Input: Output:
[1, 2, 3, 4, 5] [1, 2, 3, 4, 5]
Input: Output:
[0, 0, 0, 0, 0, 0, 0, 0] [0, 9, 0, 9, 0, 9, 0, 100]
[9, 9, 9, 9, 9, 9, 9, 100] [9, 0, 9, 0, 9, 0, 9, 0]
[0, 0, 0, 0, 0, 0, 0, 0] [0, 9, 0, 9, 0, 9, 0, 100]
Input: Output:
[0, 1, 2, 3, 4, 5] [0, 7, 14, 9, 4, 11]
[6, 7, 8, 9, 10, 11] [6, 1, 8, 15, 10, 5]
[12, 13, 14, 15, 16, 17] [12, 7, 2, 9, 16, 11]
Input: Output:
[0, 0, 0, 0, 0, 0] [0, 2, 2, 6, 2, 6]
[1, 2, 3, 4, 5, 6] [1, 0, 3, 2, 5, 2]
[2, 2, 2, 2, 2, 2] [2, 2, 0, 4, 2, 4]
[9, 8, 7, 6, 5, 4] [9, 2, 3, 0, 5, 2]
This is code-golf, so the submission with the least amount of bytes wins!
2Jelly wins this. – lirtosiast – 2016-01-22T18:22:44.273
Can you please add a three-array testcase where the last array is different then the first, and a four-array testcase? – ETHproductions – 2016-01-22T19:11:24.027
1I can't find the problem description. Can anyone tell me where it is? – feersum – 2016-01-22T19:14:09.393
Yes. I can't find a description of the task. – feersum – 2016-01-22T19:20:01.910
I don't have any idea what a "bounced array" is. – feersum – 2016-01-22T19:22:34.540
It took me a few reads, but it's actually there. The bounced arrays are things you read from the input in the three examples that have the
_
in them. Basically, for each cell on the left there's a bounced array that you get by starting to reading along the north-east diagonal and reflecting off the top and bottom. (This could definitely be clearer though.) – Martin Ender – 2016-01-22T19:31:16.960What do you mean "the path is pointed upwards"? Where does the path start from? If it's from left, why some paths go up and other go down? The challenge sounds interesting but please explain – Luis Mendo – 2016-01-22T21:43:15.447
Got it. Thanks @Martin and thanks to the examples – edc65 – 2016-01-22T22:06:29.500
@LuisMendo let's check if I really got it. The path goes left to right and starts going up, except when the start is at line 0. In that case the path immediately "bounce" down – edc65 – 2016-01-22T22:09:11.570
@edc65 Maye so... but "except when the start is at line 0" is a weird rule, isn't it? – Luis Mendo – 2016-01-22T22:12:47.507
1@LuisMendo it's the only way to bounce, at line 0 it can't go up more – edc65 – 2016-01-22T22:15:23.757
@edc65 Got it. You could think it always goes up, but at line 0 it has to immediately bounce down. Thanks! – Luis Mendo – 2016-01-22T22:16:45.317
Consider adding "zig-zag" or something similar, maybe a few (animated?) images of the ball following its path; I had to read the entire post to figure out what you meant. – wizzwizz4 – 2016-01-23T12:17:34.823