tag:blogger.com,1999:blog-6395743605854105890.post6092156328848379546..comments2019-01-30T08:46:42.876-08:00Comments on COIN DOOR INTERLOCK: bubble vs decorated sortRodneyliveshttp://www.blogger.com/profile/03476187929555342435noreply@blogger.comBlogger3125tag:blogger.com,1999:blog-6395743605854105890.post-24979906051571134102013-03-23T17:02:14.940-07:002013-03-23T17:02:14.940-07:00Almost a full year later, I know, but I wanted to ...Almost a full year later, I know, but I wanted to point out that Python allows swapping variable values without using a temp variable. You simply do<br /><br />a, b = b, a<br /><br />:)Henréhttps://www.blogger.com/profile/16138070741015006245noreply@blogger.comtag:blogger.com,1999:blog-6395743605854105890.post-74064197689748861602012-05-28T18:24:35.620-07:002012-05-28T18:24:35.620-07:00It's too early to be concerned about their beh...It's too early to be concerned about their behaviors being a bit different, in tests they're both close enough to what I want.<br /><br />My idea is to implement one or the other and see what the consequences is to the simulation. At the moment, I've realized, both solutions are better at simulating falling liquids than my current setup, which is basically to separate tiles into empty and fluid, then handle separately both flow between cells and inside the same cell. It'd be both simpler, and potentially faster, to handle fluids as a bunch of columns of space, treating air as basically the lightest fluid.<br /><br />I'm proceeding by programming experimentally, trying some algorithms that do generally what I want, more than designing it all first and going from there. It's an approach that's worked well for me in the past, but it helps that the end state is still in some flux.Rodneyliveshttps://www.blogger.com/profile/03476187929555342435noreply@blogger.comtag:blogger.com,1999:blog-6395743605854105890.post-10425710528030493232012-05-28T18:16:36.365-07:002012-05-28T18:16:36.365-07:00enumerate(sortlist) is equivalent to templist, exc...enumerate(sortlist) is equivalent to templist, except that enumerate() returns an iterable instead of a list, and the index is before the item.<br /><br />(x for y in z) makes a generator.<br />[x for y in z] makes a list.<br />This is true in python 2.x and python 3.x. Python 3.x (and maybe 2.7) added similar syntax for making dictionaries and sets.<br /><br />You can pass a key function to sort(), but generally every time I use it for something CPU-bound I find that it's better to put the keys in a tuple as you have done.<br /><br />It's probably possible to do a bubble sort with list comprehensions, but you'd have to twist them beyond all recognition to make it work.<br /><br />It bothers me that the bubble sort and decsortundec are semantically different, and you don't seem very concerned with the semantics.Vincent Povirkhttps://www.blogger.com/profile/13165914103500287643noreply@blogger.com