import math as m import random as r bombs = 20 dist = [[bombs]] lst = [bombs] while len(lst) < bombs: idx = list(lst+[1]).index(1) - 1 # index of last non-1 value oval = lst[idx] # last non-1 value tval = oval - 1 # target max value of collapse total = sum(lst[idx:]) # sum of collapse (of lst, from idx to end, inclusive) # print("LIST: " + str(lst)) # print(" oVal: " + str(oval)) # print(" tVal: " + str(tval)) # print(" Totl: " + str (total)) lst = lst[:idx] # remains of collapse (lst, up to idx, non-inclusive) cotton = list(int(tval) for i in range(0,int(total/tval))) tail = total % tval if tail: lst += cotton + [tail] else: lst += cotton dist += [lst] print("TOTAL DISTRIBUTIONS: " + str(len(dist))) for i in dist: print(i)
Run
Reset
Share
Import
Link
Embed
Language▼
English
中文
Python Fiddle
Python Cloud IDE
Follow @python_fiddle
Browser Version Not Supported
Due to Python Fiddle's reliance on advanced JavaScript techniques, older browsers might have problems running it correctly. Please download the latest version of your favourite browser.
Chrome 10+
Firefox 4+
Safari 5+
IE 10+
Let me try anyway!
url:
Go
Python Snippet
Stackoverflow Question