CASIO Graph 90+E
|
09-03-2018, 05:52 PM
(This post was last modified: 09-03-2018 06:18 PM by gomefun2.)
Post: #50
|
|||
|
|||
RE: CASIO Graph 90+E
Your code works but could be made faster.
I also ran your code and got about 29 seconds, then I watched this video: https://www.youtube.com/watch?v=hHec4qL00x0 I only followed his first point of advice by making your code a function by adding one single line of code I sped up your code from 29 seconds down to 13 seconds! I didn't really watch the rest of the video yet to see if there are even more things that could be done. I'm not a computer scientist though, more of an engineer, and I don't really use python too much. def XXX(n): for i in range(n): a = [0] * 9 r = 8 s = 0 x = 0 y = 0 t = 0 while True: x += 1 a[x] = r while True: s += 1 y = x while y>1: y -= 1 t = a[x]-a[y] if t==0 or x-y==abs(t): y=0 a[x] -= 1 while a[x]==0: x -= 1 a[x] -= 1 if y==1: break; if x==r: break; print(s) |
|||
« Next Oldest | Next Newest »
|
User(s) browsing this thread: 3 Guest(s)