Skip to content

Instantly share code, notes, and snippets.

@SproutSeeds
Created April 9, 2019 01:48
Show Gist options
  • Select an option

  • Save SproutSeeds/6fa004ec3ffaea038df7148edc4a3a20 to your computer and use it in GitHub Desktop.

Select an option

Save SproutSeeds/6fa004ec3ffaea038df7148edc4a3a20 to your computer and use it in GitHub Desktop.
cellCompete - Code Challenge
cell_arr = [0,1,0,1,1,0,0,1]
# Answer for 1 day should be...
# arr = [1,0,0,1,1,1,1,0]
# Answer for 2 days should be...
# arr = [0,1,1,1,0,0,1,1]
# Answer for 3 days should be...
# arr = [1,1,0,1,1,1,1,1]
def cellCompete(arr, num_of_days):
new_arr = []
for j in range(num_of_days):
for i in range(len(arr)):
if i == 0:
if arr[i+1] == 0:
new_arr.append(0)
else:
new_arr.append(1)
elif i == (len(arr) - 1):
if arr[i-1] == 0:
new_arr.append(0)
else:
new_arr.append(1)
else:
if arr[i-1] == arr[i+1]:
new_arr.append(0)
else:
new_arr.append(1)
arr = new_arr
new_arr = []
return arr
print(cellCompete(cell_arr, 3))
@lkelly93
Copy link

lkelly93 commented Apr 9, 2019

Nice job bro.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment