t3=[] t4=[] t5=[] t6=[] t7=[] t8=[] s3=[] e3=[] s4=[] e4=[] s5=[] e5=[] s6=[] e6=[] s7=[] e7=[] s8=[] e8=[] starts=[] ends=[] for n in range(18,143): f3=n*(n-1)/2 f4=n*n f5=n*(3*n-1)/2 f6=n*(2*n-1) f7=n*(5*n-3)/2 f8=n*(3*n-2) if f3>999 and f3<10000: t3.append (f3) s3.append (int(f3/100)) e3.append(f3%100) if f4>999 and f4<10000: t4.append (f4) s4.append (int(f4/100)) e4.append(f4%100) if f5>999 and f5<10000: t5.append (f5) s5.append (int(f5/100)) e5.append(f5%100) if f6>999 and f6<10000: t6.append (f6) s6.append (int(f6/100)) e6.append(f6%100) if f7>999 and f7<10000: t7.append (f7) s7.append (int(f7/100)) e7.append(f7%100) if f8>999 and f8<10000: t8.append (f8) s8.append (int(f8/100)) e8.append(f8%100) starts=[s3,s4,s5,s6,s7,s8] ends=[e3,e4,e5,e6,e7,e8] tots=[t3,t4,t5,t6,t7,t8] n=1 el = [1,2,3,4,5] names=[" ","square","pent","hex","hept","oct"] print (el) snippet =[] snip=[] target=10000 while n<target: for a in range (4): if a==8: snippet = [el[0]+1] spot = el.index(el[0]+1) del el[spot] el.sort() el=snippet+el print (el) break if el[3-a]<el[4-a]: basis=el[3-a] snip=el[3-a:] spot=0 b=basis+1 while b<5: if b in snip: spot = b break b=b+1 snippet = [b] spot = snip.index(b) del snip[spot] snip.sort() del el[len(el)-len(snip)-1:] el =el+snippet+snip print("tri",names[el[0]],names[el[1]],names[el[2]],names[el[3]],names[el[4]]) for a in range(len(ends[0])): for b in range(len(starts [el[0]])): if ends[0][a]==starts[el[0]][b]: for c in range(len(starts[el[1]])): if ends[el[0]][b]==starts[el[1]][c]: for d in range(len(starts[el[2]])): if ends[el[1]][c]==starts[el[2]][d]: for e in range(len(starts[el[3]])): if ends[el[2]][d]==starts[el[3]][e]: for f in range(len(starts[el[4]])): if ends[el[3]][e]==starts[el[4]][f]: if ends[el[4]][f]==starts[0][a]: print(tots[0][a],tots[el[0]][b], tots[el[1]][c], tots[el[2]][d], tots[el[3]][e],tots[el[4]][f]) break n=n+1
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