Name: Anonymous 2011-10-15 17:16
I'm trying to write a simple program in C# that does the following:
I have an array of integers numbered sequentially from 1 to 2000. I loop through and discard the first integer, and move the second integer to the end of the array. Then I discard the 3rd, and the 4th becomes the end integer. Discard the 5th, and the 6th becomes the end integer, etc.
This process will continue until it ultimately ends in one last integer remaining. How do I find it?
A smaller example of what I'm talking about from 1 to 10:
Start with [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
Then [3 4 5 6 7 8 9 10 2]
Then [5 6 7 8 9 10 2 4]
Then [7 8 9 10 2 4 6]
Then [9 10 2 4 6 8]
Then [2 4 6 8 10]
Then [6 8 10 4]
Then [10 4 8]
Then [8 4]
Finally ending with [4]
And I'm not sure whether to use an array and somehow remove numbers from it (changing its size dynamically)or maybe to use a List<int>?
I have an array of integers numbered sequentially from 1 to 2000. I loop through and discard the first integer, and move the second integer to the end of the array. Then I discard the 3rd, and the 4th becomes the end integer. Discard the 5th, and the 6th becomes the end integer, etc.
This process will continue until it ultimately ends in one last integer remaining. How do I find it?
A smaller example of what I'm talking about from 1 to 10:
Start with [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
Then [3 4 5 6 7 8 9 10 2]
Then [5 6 7 8 9 10 2 4]
Then [7 8 9 10 2 4 6]
Then [9 10 2 4 6 8]
Then [2 4 6 8 10]
Then [6 8 10 4]
Then [10 4 8]
Then [8 4]
Finally ending with [4]
And I'm not sure whether to use an array and somehow remove numbers from it (changing its size dynamically)or maybe to use a List<int>?