-
-
Save SproutSeeds/6fa004ec3ffaea038df7148edc4a3a20 to your computer and use it in GitHub Desktop.
cellCompete - Code Challenge
This file contains hidden or 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
| 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)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Nice job bro.