You are viewing a single comment's thread. Return to all comments →
I don't try to compress code. So you cat read it and make observations.
def whatsNext(arr): if len(arr)==0: ret = [] elif len(arr)==1: arr[-1] -= 1 ret = [1]+[1]+[arr[-1]] elif len(arr)==2: arr[-1] += 1 arr[-2] -= 1 ret = [1]+[arr[-1]]+[arr[-2]] elif len(arr)%2!=0: arr[-1] -= 1 arr[-2] -= 1 ret = arr[:-1]+[1]+[1]+[arr[-1]] else: arr[-1] += 1 arr[-2] -= 1 arr[-3] -= 1 ret = arr[:-2]+[1]+[arr[-1]]+[arr[-2]] if len(ret)>2: for i in range(1,len(ret)-1): if ret[i]==0 and ret[i+1]==1: ret[i-1] += 1 ret[i+1] = None ret = list(filter(bool,ret)) print(len(ret)) print(*ret)
Seems like cookies are disabled on this browser, please enable them to open this website
What's Next?
You are viewing a single comment's thread. Return to all comments →
I don't try to compress code. So you cat read it and make observations.