Ad
  • Custom User Avatar
  • Custom User Avatar

    As I understand it, you need to write a function which takes an array, and returns another array. To populate the output array, go through the input, and select every other item. Once you reach the end, loop through the input array again with the same pattern, ignoring the items which were "selected" previously. However, when you restart the array, the decision to either include or exclude an item doesn't reset. So if you selected the last item, ignore the first item when you restart the array.

    For example, take the array [1, 2, 3, 4, 5]

    First, go through every other element, like so:

             Y  N  Y  N  Y
    input:  [1, 2, 3, 4, 5]
             |    _|  ___|
             |   |   | 
    output: [1,  3,  5]
    

    After "removing" these elements, we are left with [2, 4], so we repeate the same pattern. However, because our last runthrough ended with a "Yes", this new runthrough starts with a "No":

             N  Y
    input:  [2, 4]
                |_____
                      |
    output: [1, 3, 5, 4]
    

    Now, since only [2] is left in our input form, we add it to the end of the output, returning [1, 3, 5, 4, 2].

    Hopefully that makes a bit more sense.

  • Custom User Avatar

    This comment is hidden because it contains spoiler information about the solution

  • Custom User Avatar

    Such a confusing description