Created
November 8, 2018 08:29
-
-
Save sharuzzaman/6a323ad8ce464ab3668355048015ad7a to your computer and use it in GitHub Desktop.
python array elimination
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/env python | |
import sys | |
input=int(sys.argv[1])+1 | |
array=range(1,input) | |
print array | |
def remove_left(myarray): | |
return myarray[1::2] | |
def remove_right(myarray): | |
myarray=myarray[-2::-2] | |
if len(myarray) > 1: | |
myarray.reverse() | |
return myarray | |
while len(array) > 1: | |
array=remove_left(array) | |
print array | |
if len(array) > 1: | |
array=remove_right(array) | |
print array |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment