<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0"><channel><title>Disqus - Latest Comments for Paddy3118</title><link>http://disqus.com/people/89f032bea7ea14c8157aaa72a243bd06/</link><description></description><language>en</language><lastBuildDate>Wed, 24 Jun 2009 15:11:06 -0000</lastBuildDate><item><title>Re: My new ticket tracking system is now vaporware!</title><link>http://tplus1.disqus.com/my_new_ticket_tracking_system_is_now_vaporware/#comment-6493548</link><description>Graphs. When to ship often depends on looking at graphs of bugs/time fixes/time and a lot of guesswork.&lt;br&gt;&lt;br&gt;- Paddy.</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Paddy3118</dc:creator><pubDate>Mon, 23 Feb 2009 02:57:26 -0000</pubDate></item><item><title>Re: Instead of setting instance attributes within __init__</title><link>http://tplus1.disqus.com/instead_of_setting_instance_attributes_within___init__/#comment-7488400</link><description>Hi,&lt;br&gt;Every property takes 5 lines instead of 1? And you were worried about length???&lt;br&gt;&lt;br&gt;You could call a separate method from init to do the setting.&lt;br&gt;&lt;br&gt;- Paddy.</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Paddy3118</dc:creator><pubDate>Wed, 25 Mar 2009 03:44:16 -0000</pubDate></item><item><title>Re: Revisiting Python</title><link>http://codefluency.disqus.com/revisiting_python/#comment-4800857</link><description>F.Y.I...&lt;br&gt;  &lt;a href="http://cbcg.net/2007/04/22/python-up-ruby-down-if-that-runtime-dont-work-then-its-bound-to-drizzown.html" rel="nofollow"&gt;http://cbcg.net/2007/04/22/python-up-ruby-down-...&lt;/a&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Paddy3118</dc:creator><pubDate>Wed, 31 Dec 2008 13:46:08 -0000</pubDate></item><item><title>Re: Performance Comparison - C++ / Java / Python / Ruby/ Jython / JRuby / Groovy</title><link>http://var-log-mind.disqus.com/performance_comparison_c_java_python_ruby_jython_jruby_groovy/#comment-1209681</link><description>Hi Dhananjay,&lt;br&gt;&lt;br&gt;I decided to do a more idiomatic solution in Python than your one. As you yourself state, the Python solution closely follows the static language solutions and so it is handicapped.&lt;br&gt;&lt;br&gt;I came up with this:&lt;br&gt;&lt;br&gt;..def findlast(chainlength = 40, kill = 3):&lt;br&gt;....firstinc, c = 1, range(1,chainlength + 1)&lt;br&gt;....while len(c)1:&lt;br&gt;........#print firstinc, c&lt;br&gt;........c, firstinc = [x for n,x in enumerate(c) if (firstinc+n) % 3], \&lt;br&gt;......................(n+1 +firstinc) %3&lt;br&gt;....#print firstinc, c&lt;br&gt;....return c&lt;br&gt;&lt;br&gt;(Replace initial dots with spaces)&lt;br&gt;&lt;br&gt;The run time was around four times faster, and its is only SIX lines of code versus the ~33 lines of your static-like classes.&lt;br&gt;&lt;br&gt;Here is my timings:&lt;br&gt;&lt;br&gt;Time per iteration for Chain = 386.570000648 microseconds &lt;br&gt;Time per iteration for findlast = 94.0599989891 microseconds &lt;br&gt;&lt;br&gt;If you remove the # from the print statements you get printouts to help show what is happeneing. &lt;br&gt;&lt;br&gt;To create this I used Pythons interactive shell to play around with removing positions in a list, then on how to wrap around and remove more positions from the start of the reduced list. After the experimentation it was straight forward to create the function, (not everything needs to be a class).&lt;br&gt;&lt;br&gt;I note that your result of Chain(40).kill(3).count == 27 wheras I get findlast() == 28&lt;br&gt;On looking closer at your lines 18 and 19 I see that you are counting Persons from zero when the problem statement says count from 1. You need to make sure that you don't get an off-by-one error when you report the position as someones life could be at stake :-)&lt;br&gt;&lt;br&gt;All-in-all I am quite happy with finding a solution with Python, I can concentrate on getting the algorithm right. If I need it faster then I would probably translate the Python algorithm or use the psycho JIT compiler.&lt;br&gt;&lt;br&gt;- Paddy.</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Paddy3118</dc:creator><pubDate>Tue, 08 Jul 2008 14:33:02 -0000</pubDate></item><item><title>Re: Performance Comparison - C++ / Java / Python / Ruby/ Jython / JRuby / Groovy</title><link>http://var-log-mind.disqus.com/performance_comparison_c_java_python_ruby_jython_jruby_groovy/#comment-1209684</link><description>Hi again,&lt;br&gt;With a simple addition of two lines (OK and the prior installation of the non-standard package called psyco)&lt;br&gt;The Psyco JIT compiler gave the following faster times on the same box:&lt;br&gt;&lt;br&gt;Time per iteration for findlast = 32.1899986267 microseconds &lt;br&gt;Time per iteration for Chain = 109.370000362 microseconds &lt;br&gt;&lt;br&gt;So, that is an order of magnitude speed up.&lt;br&gt;&lt;br&gt;- Paddy..</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Paddy3118</dc:creator><pubDate>Tue, 08 Jul 2008 15:27:12 -0000</pubDate></item><item><title>Re: Performance Comparison - C++ / Java / Python / Ruby/ Jython / JRuby / Groovy</title><link>http://var-log-mind.disqus.com/performance_comparison_c_java_python_ruby_jython_jruby_groovy/#comment-1209695</link><description>Hi again Dhananjay,&lt;br&gt;&lt;br&gt;I made a slightly different version using izip() and count(). It is no fasterbut might be even easier to show how the python list is used as a circular list.&lt;br&gt;It also has the two lines needed for optimising with psyco. &lt;br&gt;&lt;br&gt;..from itertools import izip, count&lt;br&gt;..import psyco&lt;br&gt;..psyco.full()&lt;br&gt;..def findlast2(chainlength = 40, kill = 3):&lt;br&gt;......n, c = 0, range(1,chainlength + 1)&lt;br&gt;......while len(c)1:&lt;br&gt;..........#print "n=%3i, (n+1)%%3=%i, c=%s" % (n, (n+1)%3, c)&lt;br&gt;..........c = [x for n,x in izip(count(n+1),c) if n % 3]&lt;br&gt;......#print "n=%3i, (n+1)%%3=%i, c=%s" % (n, (n+1)%3, c)&lt;br&gt;......return c&lt;br&gt;&lt;br&gt;&lt;br&gt;Again, if you un-comment the print statements and call findlast2() you get a better insight into the algorithm as it will return:&lt;br&gt;&lt;br&gt; findlast2()&lt;br&gt;n=  0, (n+1)%3=1, c=[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40]&lt;br&gt;n= 40, (n+1)%3=2, c=[1, 2, 4, 5, 7, 8, 10, 11, 13, 14, 16, 17, 19, 20, 22, 23, 25, 26, 28, 29, 31, 32, 34, 35, 37, 38, 40]&lt;br&gt;n= 67, (n+1)%3=2, c=[1, 4, 5, 8, 10, 13, 14, 17, 19, 22, 23, 26, 28, 31, 32, 35, 37, 40]&lt;br&gt;n= 85, (n+1)%3=2, c=[1, 5, 8, 13, 14, 19, 22, 26, 28, 32, 35, 40]&lt;br&gt;n= 97, (n+1)%3=2, c=[1, 8, 13, 19, 22, 28, 32, 40]&lt;br&gt;n=105, (n+1)%3=1, c=[1, 13, 19, 28, 32]&lt;br&gt;n=110, (n+1)%3=0, c=[1, 13, 28, 32]&lt;br&gt;n=114, (n+1)%3=1, c=[13, 28]&lt;br&gt;n=116, (n+1)%3=0, c=[13, 28]&lt;br&gt;n=118, (n+1)%3=2, c=[28]&lt;br&gt;[28]</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Paddy3118</dc:creator><pubDate>Wed, 09 Jul 2008 01:09:06 -0000</pubDate></item><item><title>Re: Performance Comparison - C++ / Java / Python / Ruby/ Jython / JRuby / Groovy</title><link>http://var-log-mind.disqus.com/performance_comparison_c_java_python_ruby_jython_jruby_groovy/#comment-1209696</link><description>Hi,&lt;br&gt;You concentrate on the speed of each implementation but speed is no good if it gives wrong results.&lt;br&gt;&lt;br&gt;How do you know you are getting the right result?&lt;br&gt;&lt;br&gt;I've walked through my algorithms partial results as you can see and know that I have to return 28. It was straightforward to do in Pythons shell.&lt;br&gt;On researching the problem further I found this page: &lt;a href="http://mathworld.wolfram.com/JosephusProblem.html" rel="nofollow"&gt;http://mathworld.wolfram.com/JosephusProblem.html&lt;/a&gt;. Mathworld seems to be good at maths problems and I stuck their 41,3 sized problem into my algorithm with the print statements un-commented and found that my algo gave the same results of the last person being numbered 31 and the second to last being 16.&lt;br&gt;&lt;br&gt;And on that note I then tried to replicate the triangular table of results numbered (3) on the Wolfram page and came a cropper. I have to withdraw findlast() and make the following modification to findlast2() to handle the special case of choosing every soldier on order:&lt;br&gt;&lt;br&gt;..def findlast2(chainlength = 40, kill = 3):&lt;br&gt;......if kill == 1:&lt;br&gt;..........return [chainlength] &lt;br&gt;......n, c = 0, range(1,chainlength + 1)&lt;br&gt;......while len(c)1:&lt;br&gt;..........#print "n=%3i, (n+1)%%3=%i, c=%s" % (n, (n+1)%3, c)&lt;br&gt;..........c = [x for n,x in izip(count(n+1),c) if n % kill]&lt;br&gt;......#print "n=%3i, (n+1)%%3=%i, c=%s" % (n, (n+1)%3, c)&lt;br&gt;......return c&lt;br&gt;&lt;br&gt;With the following loops to create the table:&lt;br&gt;&lt;br&gt;..mx = 10&lt;br&gt;..print"\nTable showing last positions"&lt;br&gt;..print "\n%12s" % "kill every:",&lt;br&gt;..for kill in range(1,mx+1):&lt;br&gt;......print "%2i" % kill,&lt;br&gt;..print&lt;br&gt;..for chain in range(1,mx+1):&lt;br&gt;......print "\n%12s" % ("chain of %i:" % chain),&lt;br&gt;......for kill in range(1,chain+1):&lt;br&gt;..........print "%2i" % findlast2(chain, kill)[0],&lt;br&gt;..print&lt;br&gt;..&lt;br&gt;&lt;br&gt;I then get the following output that tallies with the Wolfram table:&lt;br&gt;&lt;br&gt;..Table showing last positions&lt;br&gt;..&lt;br&gt;.. kill every:  1  2  3  4  5  6  7  8  9 10&lt;br&gt;..&lt;br&gt;.. chain of 1:  1 &lt;br&gt;.. chain of 2:  2  1 &lt;br&gt;.. chain of 3:  3  3  2 &lt;br&gt;.. chain of 4:  4  1  1  2 &lt;br&gt;.. chain of 5:  5  3  4  1  2 &lt;br&gt;.. chain of 6:  6  5  1  5  1  4 &lt;br&gt;.. chain of 7:  7  7  4  2  6  3  5 &lt;br&gt;.. chain of 8:  8  1  7  6  3  1  4  4 &lt;br&gt;.. chain of 9:  9  3  1  1  8  7  2  3  8 &lt;br&gt;..chain of 10: 10  5  4  5  3  3  9  1  7  8&lt;br&gt;&lt;br&gt;&lt;br&gt;A quick modification of the table printing loop to use:&lt;br&gt;  print "%2i" % int(findlast2(chain, kill)[0] == Chain(chain).kill(kill).count+1)&lt;br&gt;Shows that by allowing for the off by one error, Your Python solution tallies with mine.&lt;br&gt;&lt;br&gt;What to glean from the above?&lt;br&gt;* Verification counts.&lt;br&gt;* Verification and exploration is easy in an interpreted language that gives concise algorithms - it is easier to "throw one away" in the quest for quality.&lt;br&gt;&lt;br&gt;- Paddy.</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Paddy3118</dc:creator><pubDate>Wed, 09 Jul 2008 02:37:26 -0000</pubDate></item><item><title>Re: Performance Comparison - C++ / Java / Python / Ruby/ Jython / JRuby / Groovy</title><link>http://var-log-mind.disqus.com/performance_comparison_c_java_python_ruby_jython_jruby_groovy/#comment-1209702</link><description>I know I'm supposed to be following the class based approach of your static language examples but I do like the problem itself.&lt;br&gt;&lt;br&gt;There is more info on the problem here:&lt;br&gt;&lt;a href="http://www.research.att.com/%7Enjas/sequences/A032434" rel="nofollow"&gt;http://www.research.att.com/~njas/sequences/A03...&lt;/a&gt;&lt;br&gt;&lt;br&gt;Including a recurrence relation that gives the answer.&lt;br&gt;&lt;br&gt;It translates into the following Python recursive function:&lt;br&gt;&lt;br&gt; def T(n, k):&lt;br&gt;....if n == 1 : return 1&lt;br&gt;....tmp = (T(n-1, k)+k) % n&lt;br&gt;....if tmp == 0:&lt;br&gt;........return n&lt;br&gt;....else:&lt;br&gt;........return tmp&lt;br&gt;&lt;br&gt;....&lt;br&gt; for n in range(1,8):&lt;br&gt;....print "\n",n,":",&lt;br&gt;....for k in range(1, n+1): print T(n, k),&lt;br&gt;&lt;br&gt;&lt;br&gt;1 : 1 &lt;br&gt;2 : 2 1 &lt;br&gt;3 : 3 3 2 &lt;br&gt;4 : 4 1 1 2 &lt;br&gt;5 : 5 3 4 1 2 &lt;br&gt;6 : 6 5 1 5 1 4 &lt;br&gt;7 : 7 7 4 2 6 3 5&lt;br&gt; T(40,3)&lt;br&gt;28&lt;br&gt; &lt;br&gt;&lt;br&gt;&lt;br&gt;If only I new enough maths to derive the above!&lt;br&gt;&lt;br&gt;Oh, here's the timings:&lt;br&gt;Time per iteration for T = 8.75 microseconds &lt;br&gt;Time per iteration for findlast2 = 93.1200003624 microseconds &lt;br&gt;Time per iteration for Chain = 221.560001373 microseconds &lt;br&gt;&lt;br&gt;&lt;br&gt;I haven't had so much fun with a sequence since Ackermanns function, and that was ages ago :-)&lt;br&gt;&lt;br&gt;- Paddy.</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Paddy3118</dc:creator><pubDate>Wed, 09 Jul 2008 14:05:04 -0000</pubDate></item><item><title>Re: Python isinstance considered useful | Dobesland</title><link>http://dobesland.disqus.com/python_isinstance_considered_useful_dobesland/#comment-2814270</link><description>Maybe some of your problem with duck typing as it is called is reflected in your first paragraph:&lt;br&gt;&lt;br&gt;  " You should instead infer what type of object you have by checking for the presence or absence of particular methods".&lt;br&gt;&lt;br&gt;That isn't quite right. You should just go ahead and use whatever object you have assuming it is the correct object and trust Pythons run-time type checking and your programming team to "do the right thing". It isn't that explicit interface checking isn't needed in Python - its just not the only way, or necessarily the first way to try when programming Python.&lt;br&gt;&lt;br&gt;- Paddy.&lt;br&gt;&lt;br&gt;Ref: &lt;a href="http://en.wikipedia.org/wiki/Duck_typing" rel="nofollow"&gt;http://en.wikipedia.org/wiki/Duck_typing&lt;/a&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Paddy3118</dc:creator><pubDate>Tue, 09 Oct 2007 01:52:01 -0000</pubDate></item><item><title>Re: More factor: tabular to triples</title><link>http://phildawesstuff.disqus.com/more_factor_tabular_to_triples/#comment-2753622</link><description>I thought from the input format and the output that a Python list comprehension would be the way I'd solve it and came up with this:&lt;br&gt;&lt;br&gt;&amp;gt;&amp;gt;&amp;gt; from pprint import pprint as pp&lt;br&gt;&amp;gt;&amp;gt;&amp;gt; tabular = [["col1","col2","col3"],[["a","b","c"],["e","f","g"]]]&lt;br&gt;&amp;gt;&amp;gt;&amp;gt; triples = [(row[0], col[1], row[1][col[0]])  &lt;br&gt;  for row in enumerate(tabular[1]) &lt;br&gt;  for col in enumerate(tabular[0])]&lt;br&gt;&amp;gt;&amp;gt;&amp;gt; pp(triples)&lt;br&gt;[(0, 'col1', 'a'),&lt;br&gt; (0, 'col2', 'b'),&lt;br&gt; (0, 'col3', 'c'),&lt;br&gt; (1, 'col1', 'e'),&lt;br&gt; (1, 'col2', 'f'),&lt;br&gt; (1, 'col3', 'g')]&lt;br&gt;&amp;gt;&amp;gt;&amp;gt; &lt;br&gt;&lt;br&gt;&lt;br&gt;(I added a couple of newlines to the list comprehension to get it into the comment box).&lt;br&gt;&lt;br&gt;If I were using it then I might wrap it in a function and add a docstring to test/explain it.&lt;br&gt;&lt;br&gt;- Paddy.</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Paddy3118</dc:creator><pubDate>Fri, 12 Oct 2007 00:55:43 -0000</pubDate></item><item><title>Re: Generating pseudo random text with Markov chains using Python</title><link>http://usware.disqus.com/generating_pseudo_random_text_with_markov_chains_using_python/#comment-16047595</link><description>You don't seem to use the relative frequenccy of next words to weight the random choice?&lt;br&gt;&lt;br&gt;- Paddy.</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Paddy3118</dc:creator><pubDate>Tue, 23 Jun 2009 17:17:03 -0000</pubDate></item><item><title>Re: Generating pseudo random text with Markov chains using Python</title><link>http://usware.disqus.com/generating_pseudo_random_text_with_markov_chains_using_python/#comment-16047597</link><description>Thanks, I missed that!</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Paddy3118</dc:creator><pubDate>Wed, 24 Jun 2009 15:11:06 -0000</pubDate></item></channel></rss>