<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Lee Braiden&#039;s Blog &#187; Development</title>
	<atom:link href="http://irukado.org/category/it/foss/development/feed" rel="self" type="application/rss+xml" />
	<link>http://irukado.org</link>
	<description>Peace, Love, Tech, and random life stuff.</description>
	<lastBuildDate>Thu, 08 Oct 2009 00:10:38 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Google Chrome Frame</title>
		<link>http://irukado.org/2009/09/25/google-chrome-frame</link>
		<comments>http://irukado.org/2009/09/25/google-chrome-frame#comments</comments>
		<pubDate>Fri, 25 Sep 2009 00:32:04 +0000</pubDate>
		<dc:creator>Lee</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[FOSS]]></category>
		<category><![CDATA[IT]]></category>

		<guid isPermaLink="false">http://irukado.org/?p=1549</guid>
		<description><![CDATA[In a move right out of The Art of War, Google have announced Google Chrome Frame, which turns IE into Google Chrome.  Obviously great for web developers (django or otherwise) who want an up to date, standardised web platform on major browsers.
It seems Google haven&#8217;t really studied the book though, as they&#8217;re not making [...]]]></description>
			<content:encoded><![CDATA[<p>In a move right out of <a href="">The Art of War</a>, Google have announced <a href="http://blog.chromium.org/2009/09/introducing-google-chrome-frame.html">Google Chrome Frame, which turns IE into Google Chrome</a>.  Obviously great for web developers (django or otherwise) who want an up to date, standardised web platform on major browsers.</p>
<p>It seems Google haven&#8217;t really studied the book though, as they&#8217;re not making this happen naturally or with minimum effort &#8212; virally, in modern business speak.  If Google Chrome Frame installed in IE for some site as readily as flash installs, this would be a hugely significant release.  Seems they&#8217;ve missed a trick here.</p>
]]></content:encoded>
			<wfw:commentRss>http://irukado.org/2009/09/25/google-chrome-frame/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Blitzen: Django app installation, only faster</title>
		<link>http://irukado.org/2009/09/16/blitzen-django-app-installation-only-faster</link>
		<comments>http://irukado.org/2009/09/16/blitzen-django-app-installation-only-faster#comments</comments>
		<pubDate>Wed, 16 Sep 2009 11:32:03 +0000</pubDate>
		<dc:creator>Lee</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[FOSS]]></category>
		<category><![CDATA[IT]]></category>
		<category><![CDATA[applications]]></category>
		<category><![CDATA[automatic]]></category>
		<category><![CDATA[dependencies]]></category>
		<category><![CDATA[django]]></category>
		<category><![CDATA[framework]]></category>
		<category><![CDATA[load]]></category>
		<category><![CDATA[plugin]]></category>
		<category><![CDATA[projects]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[secret keys]]></category>
		<category><![CDATA[templates]]></category>
		<category><![CDATA[web development]]></category>

		<guid isPermaLink="false">http://irukado.org/?p=1544</guid>
		<description><![CDATA[I just noticed a <a target="_blank" href="http://opensource.washingtontimes.com/blog/post/coordt/2009/09/request-comments-auto-installation-apps-django/">Request for Comments: Auto-Installation of Apps in Django</a> by Corey Oordt, which ties in with something I've been meaning to finish up and publish.  Some time ago, I blogged about <a target="_blank" href="http://irukado.org/2009/01/12/pluggable-django-git-templates-for-turnkey-projects-and-apps/">Pluggable Django</a> and <a href="http://irukado.org/page/3/">How I hate repetiting myself</a>.  Since then, I've been re-working this code a little.  It hasn't been high priority, since django is not a tool I've needed on current projects, but I did manage to get something up on github a few days back:]]></description>
			<content:encoded><![CDATA[<p>I just noticed a <a href="http://opensource.washingtontimes.com/blog/post/coordt/2009/09/request-comments-auto-installation-apps-django/">Request for Comments: Auto-Installation of Apps in Django</a> by Corey Oordt, which ties in with something I&#8217;ve been meaning to finish up and publish.</p>
<p>Some time ago, I blogged about <a href="http://irukado.org/2009/01/12/pluggable-django-git-templates-for-turnkey-projects-and-apps/">Pluggable Django</a> and <a href="http://irukado.org/page/3/">How I hate repetiting myself</a>.  That was mostly about current but messy code I was using, which allowed me to automatically add decoupled apps to a django project without having modify the rest of my django project each time.  Apps were auto-detected, and loaded, including templates etc.</p>
<p>Since then, I&#8217;ve been re-working this code a little.  It hasn&#8217;t been high priority, since django is not a tool I&#8217;ve needed on current projects, but I did manage to get something up on github a few days back:</p>
<ul>
<li><a href="http://github.com/jel/blitzen_project">Blitzen Project</a></li>
<li><a href="http://github.com/jel/blitzen_app">Blitzen App</a></li>
</ul>
<p>So basically, these are git repositories for &#8220;django-admin startproject&#8221; and &#8220;./manage.py startapp&#8221; replacements.  To start a project, just clone the Blitzen project url, and to create an app within that, clone the Blitzen app url.  Note that most of the new code here is in a directory called quickening, which was a previous working title for this stuff.</p>
<p>So what does it do?  Well, currently, not as much as my old code, in that it doesn&#8217;t really handle templates etc. just yet (the code might be there for that, but it&#8217;s untested).  Things you&#8217;ll notice:</p>
<ul>
<li>settings.py is a <em>lot</em> more manageable.  Most of the complex config is moved into the library code and called</li>
<li>Load order of middleware is worked out automatically, by specifying dependencies.  Code for this is very straightforward, in quickening/deps.py, with the dependencies currently in quickening/apps.py</li>
<li>If I recall correctly, app dependencies aren&#8217;t handled yet, but the middleware dependency code was written to also support automatic dependency resolution for apps, including specifying dependencies within an app itself, rather than in the project that hosts an app.  More work on this is probably required.</li>
<li>there is no default SECRET_KEY any more.  Instead, secret keys are auto-generated and kept in files which are ignored by git, meaning that when you checkout the code, or push the code to a webserver, each new instance gets its own key automatically.</li>
<li>sqlite is configured by default</li>
</ul>
<p>Ideas, suggestions, flames, code, etc. welcome <img src='http://irukado.org/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://irukado.org/2009/09/16/blitzen-django-app-installation-only-faster/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PySide &#8211; Nokia releases official Python-Qt bindings</title>
		<link>http://irukado.org/2009/08/19/pyside-nokia-releases-official-python-qt-bindings</link>
		<comments>http://irukado.org/2009/08/19/pyside-nokia-releases-official-python-qt-bindings#comments</comments>
		<pubDate>Wed, 19 Aug 2009 16:40:25 +0000</pubDate>
		<dc:creator>Lee</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[FOSS]]></category>
		<category><![CDATA[IT]]></category>
		<category><![CDATA[bindings]]></category>
		<category><![CDATA[gpl]]></category>
		<category><![CDATA[gui]]></category>
		<category><![CDATA[lgpl]]></category>
		<category><![CDATA[libraries]]></category>
		<category><![CDATA[nokia]]></category>
		<category><![CDATA[pyqt]]></category>
		<category><![CDATA[pyside]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[qt]]></category>
		<category><![CDATA[qt4]]></category>
		<category><![CDATA[ui]]></category>
		<category><![CDATA[user interface]]></category>
		<category><![CDATA[widgets]]></category>

		<guid isPermaLink="false">http://irukado.org/archives/2009/08/pyside-nokia-releases-official-python-qt-bindings/</guid>
		<description><![CDATA[Seems Nokia have released official Python-Qt bindings, called PySide, which are LGPL&#8217;d.
Apparently they tried to talk Riverbank Computing into releasing the PyQt bindings as LGPL, but Riverbank wouldn&#8217;t cooperate.  Presumably Riverbank wanted Nokia to pay them a stack of money, forgetting that Nokia, owning Qt, could undercut them by just rewriting the thing themselves.
Either [...]]]></description>
			<content:encoded><![CDATA[<p>Seems Nokia have released official Python-Qt bindings, called <a href="http://www.pyside.org/">PySide</a>, which are LGPL&#8217;d.</p>
<p>Apparently they tried to talk Riverbank Computing into releasing the PyQt bindings as LGPL, but Riverbank wouldn&#8217;t cooperate.  Presumably Riverbank wanted Nokia to pay them a stack of money, forgetting that Nokia, owning Qt, could undercut them by just rewriting the thing themselves.</p>
<p>Either way&#8230; this is nothing but good news for Python+Qt fans I think.  Not only do we get new, LGPL bindings, but they&#8217;re official, and will probably be better synced with official Qt releases.  Who knows?  They might even be documented <img src='http://irukado.org/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://irukado.org/2009/08/19/pyside-nokia-releases-official-python-qt-bindings/feed</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Launchpad now Open Source</title>
		<link>http://irukado.org/2009/07/21/launchpad-now-open-source</link>
		<comments>http://irukado.org/2009/07/21/launchpad-now-open-source#comments</comments>
		<pubDate>Tue, 21 Jul 2009 11:16:21 +0000</pubDate>
		<dc:creator>Lee</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[business models]]></category>
		<category><![CDATA[commercial]]></category>
		<category><![CDATA[free software]]></category>
		<category><![CDATA[launchpad]]></category>
		<category><![CDATA[licensing]]></category>
		<category><![CDATA[mark shuttleworth]]></category>
		<category><![CDATA[open source]]></category>
		<category><![CDATA[proprietary]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[ubuntu]]></category>

		<guid isPermaLink="false">http://irukado.org/?p=1520</guid>
		<description><![CDATA[Canonical have now released Launchpad as open source. This is really good news, considering Shuttleworth&#8217;s previous stance, which I found quite wrong-headed.  Just having Launchpad alone as an Open Source project is great, as it&#8217;s a very powerful tool.  It&#8217;ll be interesting to see if they follow suit with the rest of Ubuntu&#8217;s [...]]]></description>
			<content:encoded><![CDATA[<p>Canonical have now <a href="http://blog.canonical.com/?p=192">released Launchpad as open source</a>. This is really good news, considering <a href="/archives/2009/05/shuttleworth-nails-his-colors-to-the-mast/">Shuttleworth&#8217;s previous stance</a>, which I found quite wrong-headed.  Just having Launchpad alone as an Open Source project is great, as it&#8217;s a very powerful tool.  It&#8217;ll be interesting to see if they follow suit with the rest of Ubuntu&#8217;s proprietary offerings.</p>
<p>Oh, and it&#8217;s written in python <img src='http://irukado.org/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://irukado.org/2009/07/21/launchpad-now-open-source/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Hello, Lifeforms!</title>
		<link>http://irukado.org/2009/07/12/hello-lifeforms</link>
		<comments>http://irukado.org/2009/07/12/hello-lifeforms#comments</comments>
		<pubDate>Sun, 12 Jul 2009 16:42:01 +0000</pubDate>
		<dc:creator>Lee</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[FOSS]]></category>
		<category><![CDATA[IT]]></category>
		<category><![CDATA[Adaptation]]></category>
		<category><![CDATA[ai]]></category>
		<category><![CDATA[artificial intelligence]]></category>
		<category><![CDATA[challenge]]></category>
		<category><![CDATA[craigslist]]></category>
		<category><![CDATA[evolution]]></category>
		<category><![CDATA[evolve]]></category>
		<category><![CDATA[free software]]></category>
		<category><![CDATA[genetic]]></category>
		<category><![CDATA[genetic algorithm]]></category>
		<category><![CDATA[gpl]]></category>
		<category><![CDATA[growth]]></category>
		<category><![CDATA[hello]]></category>
		<category><![CDATA[hello world]]></category>
		<category><![CDATA[lifeforms]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[sf bay]]></category>

		<guid isPermaLink="false">http://irukado.org/?p=1467</guid>
		<description><![CDATA[Wherein I create a python program to evolve beasties that can say hello.]]></description>
			<content:encoded><![CDATA[<p>Let&#8217;s start with the results, so everyone&#8217;s clear what this is about.</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">UmS6D0aW62+q!'%S2 (perfection:   0%) Evolving        2nd generation.
aUKahChc.5,e&amp;8:?1 (perfection:   0%) Evolving        3rd generation.
bYJo$F?O2;aTV'q'? (perfection:   0%) Evolving        4th generation.
P]N0+dC=p-GVh&lt;p1E (perfection:   0%) Evolving        5th generation.
P]N0+dC=p-GPQ&gt;+6b (perfection:   0%) Evolving        6th generation.
Q?T1LHOp=LSj*VUr0 (perfection:   0%) Evolving        7th generation.
ob3&lt;2Ih=p-CO^f#`5 (perfection:   0%) Evolving        8th generation.
dK8:SCn^omSj*VO ` (perfection:   0%) Evolving        9th generation.
X@Z'H&lt;f.)T?f&amp;(i6. (perfection:   6%) Evolving       10th generation.
g&amp;H0+)DG^J%GV(\(l (perfection:   0%) Evolving       11th generation.
dK9K3Vf.)T?f&amp;`Kfq (perfection:   6%) Evolving       12th generation.
8@Zm`,jZ-*jf38&quot;:; (perfection:  12%) Evolving       13th generation.
g&amp;l:7O^q0jGA2r2,&amp; (perfection:  12%) Evolving       14th generation.
j^4'N.:L0fV.9_Psi (perfection:  18%) Evolving       15th generation.
co2sL:BLffGA2((Y! (perfection:  18%) Evolving       16th generation.
MHX&lt;oUL$EP`&lt;o(\si (perfection:  18%) Evolving       17th generation.
g9l#bkrL$+e &amp;&gt;Tsr (perfection:  24%) Evolving       18th generation.
Pibho,MYilkEo(.sj (perfection:  29%) Evolving       19th generation.
cel/opLRP2aEerTs! (perfection:  35%) Evolving       20th generation.
HR(so ELrfef/\-s&amp; (perfection:  41%) Evolving       21st generation.
ce&gt;l9dr3iPef?r2sc (perfection:  41%) Evolving       22nd generation.
HRl#) EaibkforTs! (perfection:  47%) Evolving       23rd generation.
Ho9ho, LJ-?fY&gt;ms! (perfection:  53%) Evolving       24th generation.
He^j`,YLrfeHFlms! (perfection:  53%) Evolving       25th generation.
HRli*/ Lrfe &amp;rms! (perfection:  59%) Evolving       26th generation.
HelBNd Lrfe &amp;rms! (perfection:  65%) Evolving       27th generation.
HeGlo,jLifGf&amp;rm]! (perfection:  71%) Evolving       28th generation.
ce4lod &gt;iWeforms! (perfection:  71%) Evolving       29th generation.
H&amp;lho, Lif@forms! (perfection:  82%) Evolving       30th generation.
HRllo, &gt;ifeforms! (perfection:  88%) Evolving       31st generation.
Hello,:Lif@forms! (perfection:  88%) Evolving       32nd generation.
He9lo, Lifeforms! (perfection:  94%) Evolving       33rd generation.
Hello, LifeformN! (perfection:  94%) Evolving       34th generation.
HelloV Lifeforms! (perfection:  94%) Evolving       35th generation.
Hello, LifefKrms! (perfection:  94%) Evolving       36th generation.
Evolved to 100% perfection. Concluding.
&nbsp;
35,000 individuals sacrificed their lives
so that their species could eventually say:
&nbsp;
        Hello, Lifeforms!</pre></div></div>

<h2>The Challenge</h2>
<p>So&#8230; the other day, <a href="http://www.daikaiju.org.uk/~steve/cnot/">Steve</a> drew my attention to this <a href="http://sfbay.craigslist.org/sfc/eng/1246353621.html">craigslist &#8220;to all those who think themselves a programmer&#8221; challenge</a>.  To cut a long story short, the advert included a programming challenge, and mentioned that a genetic algorithm that could say Hello World using the sacrificial efforts of billions of evolving entities would be one of the winners.</p>
<p>Now, it just so happens that I wrote a pretty fun Genetic Programming app as my first foray into linux C++ programming back in the mid 90&#8217;s, and had lost the code for it.  So, last night, I rewrote a cut-down version of it in Python.</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">#!/usr/bin/env python2.6</span>
<span style="color: #808080; font-style: italic;">#</span>
<span style="color: #808080; font-style: italic;"># Copyright (c) 2009 Lee Braiden &lt;lee.b@irukado.org&gt;</span>
<span style="color: #808080; font-style: italic;"># Released under the GNU General Public License, version 3.</span>
<span style="color: #808080; font-style: italic;"># http://www.gnu.org/licenses/gpl.html for details.</span>
<span style="color: #808080; font-style: italic;">#</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">sys</span>
<span style="color: #ff7700;font-weight:bold;">from</span> <span style="color: #dc143c;">random</span> <span style="color: #ff7700;font-weight:bold;">import</span> randint, sample
&nbsp;
<span style="color: #ff7700;font-weight:bold;">class</span> Mirror:
	<span style="color: #483d8b;">&quot;&quot;&quot;Stores certain details that individuals must analyse
	and evolve themselves against.  Named after the
	psychology concept of being a mirror for an individual's
	own thoughts.&quot;&quot;&quot;</span>
	<span style="color: #ff7700;font-weight:bold;">def</span> <span style="color: #0000cd;">__init__</span><span style="color: black;">&#40;</span><span style="color: #008000;">self</span>, destiny<span style="color: black;">&#41;</span>:
		<span style="color: #483d8b;">&quot;&quot;&quot;Takes a string, 'destiny', which creatures must
		evolve to say.&quot;&quot;&quot;</span>
		<span style="color: #008000;">self</span>.<span style="color: black;">UPPER</span> = <span style="color: #008000;">max</span><span style="color: black;">&#40;</span><span style="color: black;">&#91;</span> <span style="color: #008000;">ord</span><span style="color: black;">&#40;</span>x<span style="color: black;">&#41;</span> <span style="color: #ff7700;font-weight:bold;">for</span> x <span style="color: #ff7700;font-weight:bold;">in</span> destiny <span style="color: black;">&#93;</span><span style="color: black;">&#41;</span>
		<span style="color: #008000;">self</span>.<span style="color: black;">LOWER</span> = <span style="color: #008000;">min</span><span style="color: black;">&#40;</span><span style="color: black;">&#91;</span> <span style="color: #008000;">ord</span><span style="color: black;">&#40;</span>x<span style="color: black;">&#41;</span> <span style="color: #ff7700;font-weight:bold;">for</span> x <span style="color: #ff7700;font-weight:bold;">in</span> destiny <span style="color: black;">&#93;</span><span style="color: black;">&#41;</span>
		<span style="color: #008000;">self</span>.<span style="color: black;">destiny</span> = destiny
&nbsp;
	<span style="color: #ff7700;font-weight:bold;">def</span> chromosome_len<span style="color: black;">&#40;</span><span style="color: #008000;">self</span><span style="color: black;">&#41;</span>:
		<span style="color: #483d8b;">&quot;&quot;&quot;Returns the number of chromosomes in an individual's
		genes.  In other words, this is the length of the message
		characters should evolve to say.&quot;&quot;&quot;</span>
		<span style="color: #ff7700;font-weight:bold;">return</span> <span style="color: #008000;">len</span><span style="color: black;">&#40;</span><span style="color: #008000;">self</span>.<span style="color: black;">destiny</span><span style="color: black;">&#41;</span>
&nbsp;
	<span style="color: #ff7700;font-weight:bold;">def</span> <span style="color: #008000;">range</span><span style="color: black;">&#40;</span><span style="color: #008000;">self</span><span style="color: black;">&#41;</span>:
		<span style="color: #483d8b;">&quot;&quot;&quot;A quick (readability-)helper function, which allows looping
		over each gene.&quot;&quot;&quot;</span>
		<span style="color: #ff7700;font-weight:bold;">return</span> <span style="color: #008000;">range</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">0</span>, <span style="color: #008000;">self</span>.<span style="color: black;">chromosome_len</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">class</span> Individual:
	<span style="color: #483d8b;">&quot;&quot;&quot;Represents an individual beastie which will be created, can
	breed, can mutate, can attempt to solve the problem at hand,
	and can be tested for fitness, among other things.&quot;&quot;&quot;</span>
	<span style="color: #ff7700;font-weight:bold;">def</span> <span style="color: #0000cd;">__init__</span><span style="color: black;">&#40;</span><span style="color: #008000;">self</span>, chromosome_len, mutation_rarity<span style="color: black;">&#41;</span>:
		<span style="color: #008000;">self</span>._genes =  <span style="color: #483d8b;">&quot; &quot;</span> <span style="color: #66cc66;">*</span> chromosome_len
		<span style="color: #008000;">self</span>.<span style="color: black;">fitness</span> = <span style="color: #ff4500;">0</span>
		<span style="color: #008000;">self</span>.<span style="color: black;">mutation_rarity</span> = mutation_rarity
&nbsp;
	<span style="color: #ff7700;font-weight:bold;">def</span> _gene_val<span style="color: black;">&#40;</span><span style="color: #008000;">self</span>, mirror<span style="color: black;">&#41;</span>:
		<span style="color: #483d8b;">&quot;&quot;&quot;Create a random gene value&quot;&quot;&quot;</span>
		<span style="color: #ff7700;font-weight:bold;">return</span> <span style="color: #008000;">chr</span><span style="color: black;">&#40;</span>randint<span style="color: black;">&#40;</span>mirror.<span style="color: black;">LOWER</span>, mirror.<span style="color: black;">UPPER</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>
&nbsp;
	<span style="color: #ff7700;font-weight:bold;">def</span> _randomise_genes<span style="color: black;">&#40;</span><span style="color: #008000;">self</span>, mirror<span style="color: black;">&#41;</span>:
		<span style="color: #483d8b;">&quot;&quot;&quot;Initialise all of the individual's genes randomly.  Used
		during creation, rather than breeding&quot;&quot;&quot;</span>
		<span style="color: #008000;">self</span>._genes = <span style="color: #483d8b;">&quot;&quot;</span>.<span style="color: black;">join</span><span style="color: black;">&#40;</span><span style="color: black;">&#91;</span> <span style="color: #008000;">self</span>._gene_val<span style="color: black;">&#40;</span>mirror<span style="color: black;">&#41;</span> <span style="color: #ff7700;font-weight:bold;">for</span> idx <span style="color: #ff7700;font-weight:bold;">in</span> mirror.<span style="color: #008000;">range</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span> <span style="color: black;">&#93;</span><span style="color: black;">&#41;</span>
&nbsp;
	<span style="color: #ff7700;font-weight:bold;">def</span> _choose_gene<span style="color: black;">&#40;</span><span style="color: #008000;">self</span><span style="color: black;">&#41;</span>:
		<span style="color: #483d8b;">&quot;&quot;&quot;Choose an individual gene to target.&quot;&quot;&quot;</span>
		<span style="color: #ff7700;font-weight:bold;">return</span> randint<span style="color: black;">&#40;</span><span style="color: #ff4500;">0</span>, <span style="color: #008000;">len</span><span style="color: black;">&#40;</span><span style="color: #008000;">self</span>._genes<span style="color: black;">&#41;</span>-<span style="color: #ff4500;">1</span><span style="color: black;">&#41;</span>
&nbsp;
	<span style="color: #ff7700;font-weight:bold;">def</span> _freaky<span style="color: black;">&#40;</span><span style="color: #008000;">self</span><span style="color: black;">&#41;</span>:
		<span style="color: #483d8b;">&quot;&quot;&quot;Roll a dice, and see if this individual is (un)lucky enough
		to gain a mutation.&quot;&quot;&quot;</span>
		<span style="color: #ff7700;font-weight:bold;">return</span> randint<span style="color: black;">&#40;</span><span style="color: #ff4500;">0</span>, <span style="color: #008000;">self</span>.<span style="color: black;">mutation_rarity</span><span style="color: black;">&#41;</span> == <span style="color: #ff4500;">0</span>
&nbsp;
	@<span style="color: #008000;">classmethod</span>
	<span style="color: #ff7700;font-weight:bold;">def</span> conjure<span style="color: black;">&#40;</span>cls, mirror, mutation_rarity<span style="color: black;">&#41;</span>:
		<span style="color: #483d8b;">&quot;&quot;&quot;Create an individual from scratch.&quot;&quot;&quot;</span>
		i = cls<span style="color: black;">&#40;</span><span style="color: #008000;">len</span><span style="color: black;">&#40;</span>mirror.<span style="color: black;">destiny</span><span style="color: black;">&#41;</span>, mutation_rarity<span style="color: black;">&#41;</span>
		i._randomise_genes<span style="color: black;">&#40;</span>mirror<span style="color: black;">&#41;</span>
		<span style="color: #ff7700;font-weight:bold;">return</span> i
&nbsp;
	@<span style="color: #008000;">classmethod</span>
	<span style="color: #ff7700;font-weight:bold;">def</span> breed<span style="color: black;">&#40;</span>cls, mirror, mom, dad<span style="color: black;">&#41;</span>:
		<span style="color: #483d8b;">&quot;&quot;&quot;Breed an individual from two parents.&quot;&quot;&quot;</span>
		mutation_rarity = <span style="color: #008000;">float</span><span style="color: black;">&#40;</span>mom.<span style="color: black;">mutation_rarity</span> + dad.<span style="color: black;">mutation_rarity</span><span style="color: black;">&#41;</span> / <span style="color: #ff4500;">2.0</span>
		kid = cls<span style="color: black;">&#40;</span><span style="color: #008000;">len</span><span style="color: black;">&#40;</span>mirror.<span style="color: black;">destiny</span><span style="color: black;">&#41;</span>, mutation_rarity<span style="color: black;">&#41;</span>
		x = kid._choose_gene<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
		kid._genes = <span style="color: #483d8b;">&quot;&quot;</span>.<span style="color: black;">join</span><span style="color: black;">&#40;</span>mom._genes<span style="color: black;">&#91;</span>:x<span style="color: black;">&#93;</span><span style="color: black;">&#41;</span> + <span style="color: #483d8b;">&quot;&quot;</span>.<span style="color: black;">join</span><span style="color: black;">&#40;</span>dad._genes<span style="color: black;">&#91;</span>x:<span style="color: black;">&#93;</span><span style="color: black;">&#41;</span>
		<span style="color: #ff7700;font-weight:bold;">if</span> kid._freaky<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>:
			kid._mutate<span style="color: black;">&#40;</span>mirror<span style="color: black;">&#41;</span>
		<span style="color: #ff7700;font-weight:bold;">return</span> kid
&nbsp;
	<span style="color: #ff7700;font-weight:bold;">def</span> _mutate<span style="color: black;">&#40;</span><span style="color: #008000;">self</span>, mirror<span style="color: black;">&#41;</span>:
		<span style="color: #483d8b;">&quot;&quot;&quot;Mutate a random gene&quot;&quot;&quot;</span>
		orig_genes = <span style="color: #008000;">self</span>._genes
		idx = <span style="color: #008000;">self</span>._choose_gene<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
		els = <span style="color: black;">&#91;</span> x <span style="color: #ff7700;font-weight:bold;">for</span> x <span style="color: #ff7700;font-weight:bold;">in</span> <span style="color: #008000;">self</span>._genes <span style="color: black;">&#93;</span>
		els<span style="color: black;">&#91;</span>idx<span style="color: black;">&#93;</span> = <span style="color: #008000;">self</span>._gene_val<span style="color: black;">&#40;</span>mirror<span style="color: black;">&#41;</span>
		<span style="color: #008000;">self</span>._genes = <span style="color: #483d8b;">&quot;&quot;</span>.<span style="color: black;">join</span><span style="color: black;">&#40;</span>els<span style="color: black;">&#41;</span>
&nbsp;
	<span style="color: #ff7700;font-weight:bold;">def</span> self_evaluate<span style="color: black;">&#40;</span><span style="color: #008000;">self</span>, mirror<span style="color: black;">&#41;</span>:
		<span style="color: #483d8b;">&quot;&quot;&quot;Evaluate 'fitness', or the ability to solve the given
		problem.  In other words, measure how close the individual
		is to the correct message text, and assign a score
		accordingly.&quot;&quot;&quot;</span>
		fitness = max_fitness = <span style="color: #008000;">float</span><span style="color: black;">&#40;</span><span style="color: #008000;">len</span><span style="color: black;">&#40;</span><span style="color: #008000;">self</span>._genes<span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>
&nbsp;
		<span style="color: #ff7700;font-weight:bold;">for</span> idx <span style="color: #ff7700;font-weight:bold;">in</span> <span style="color: #008000;">range</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">0</span>, <span style="color: #008000;">len</span><span style="color: black;">&#40;</span><span style="color: #008000;">self</span>._genes<span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>:
			<span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: #008000;">self</span>._genes<span style="color: black;">&#91;</span>idx<span style="color: black;">&#93;</span> == mirror.<span style="color: black;">destiny</span><span style="color: black;">&#91;</span>idx<span style="color: black;">&#93;</span>:
				<span style="color: #ff7700;font-weight:bold;">continue</span>
			<span style="color: #ff7700;font-weight:bold;">else</span>:
				fitness -= <span style="color: #ff4500;">1</span>
&nbsp;
		<span style="color: #008000;">self</span>.<span style="color: black;">fitness</span> = <span style="color: #ff4500;">100.0</span> <span style="color: #66cc66;">*</span> <span style="color: black;">&#40;</span>fitness / max_fitness<span style="color: black;">&#41;</span>
&nbsp;
	<span style="color: #ff7700;font-weight:bold;">def</span> <span style="color: #0000cd;">__cmp__</span><span style="color: black;">&#40;</span><span style="color: #008000;">self</span>, competitor<span style="color: black;">&#41;</span>:
		<span style="color: #483d8b;">&quot;&quot;&quot;Comparison function, used for sorting populations to find
		the fittest.&quot;&quot;&quot;</span>
		<span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: #008000;">self</span>.<span style="color: black;">fitness</span> <span style="color: #66cc66;">&gt;</span> competitor.<span style="color: black;">fitness</span>:
			<span style="color: #ff7700;font-weight:bold;">return</span> <span style="color: #ff4500;">1</span>
		<span style="color: #ff7700;font-weight:bold;">elif</span> <span style="color: #008000;">self</span>.<span style="color: black;">fitness</span> == competitor.<span style="color: black;">fitness</span>:
			<span style="color: #ff7700;font-weight:bold;">return</span> <span style="color: #ff4500;">0</span>
		<span style="color: #ff7700;font-weight:bold;">else</span>:
			<span style="color: #ff7700;font-weight:bold;">return</span> -<span style="color: #ff4500;">1</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">class</span> World:
	<span style="color: #483d8b;">&quot;&quot;&quot;Represents a world populated by Individuals, which breed
	together, subject to natural selection, to reach an evolutionary
	goal.&quot;&quot;&quot;</span>
	<span style="color: #ff7700;font-weight:bold;">def</span> <span style="color: #0000cd;">__init__</span><span style="color: black;">&#40;</span><span style="color: #008000;">self</span>, mirror, population_size=<span style="color: #ff4500;">1000</span>, mutation_rarity=<span style="color: #ff4500;">1000</span>, fitness_required=<span style="color: #ff4500;">100.0</span><span style="color: black;">&#41;</span>:
		<span style="color: #483d8b;">&quot;&quot;&quot;Initialise a population of population_size members, mutating
		one in every mutation_rarity breeds.  Evolution will stop when
		fitness reaches fitness_required percent.&quot;&quot;&quot;</span>
		<span style="color: #008000;">self</span>._mirror = mirror
		<span style="color: #008000;">self</span>._population = <span style="color: black;">&#91;</span> Individual.<span style="color: black;">conjure</span><span style="color: black;">&#40;</span>mirror, mutation_rarity<span style="color: black;">&#41;</span> <span style="color: #ff7700;font-weight:bold;">for</span> i <span style="color: #ff7700;font-weight:bold;">in</span> <span style="color: #008000;">range</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">0</span>, population_size<span style="color: black;">&#41;</span> <span style="color: black;">&#93;</span>
		<span style="color: #008000;">self</span>.<span style="color: black;">sacrifice_count</span> = <span style="color: #ff4500;">0</span>
		<span style="color: #008000;">self</span>._fitness_required = <span style="color: #ff4500;">100.0</span>
		<span style="color: #008000;">self</span>._mutation_rarity = mutation_rarity
&nbsp;
	<span style="color: #ff7700;font-weight:bold;">def</span> _natural_select<span style="color: black;">&#40;</span><span style="color: #008000;">self</span>, exclusion_list=<span style="color: black;">&#91;</span><span style="color: black;">&#93;</span><span style="color: black;">&#41;</span>:
		<span style="color: #483d8b;">&quot;&quot;&quot;Select two individuals from a population, choosing the most
		'fit' for breeding.&quot;&quot;&quot;</span>
		a,b = sample<span style="color: black;">&#40;</span><span style="color: #008000;">self</span>._population, <span style="color: #ff4500;">2</span><span style="color: black;">&#41;</span>
		<span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: black;">&#40;</span>a <span style="color: #66cc66;">&gt;</span> b<span style="color: black;">&#41;</span>:
			<span style="color: #ff7700;font-weight:bold;">return</span> a
		<span style="color: #ff7700;font-weight:bold;">else</span>:
			<span style="color: #ff7700;font-weight:bold;">return</span> b
&nbsp;
	<span style="color: #ff7700;font-weight:bold;">def</span> _breeding_pairs<span style="color: black;">&#40;</span><span style="color: #008000;">self</span><span style="color: black;">&#41;</span>:
		<span style="color: #483d8b;">&quot;&quot;&quot;Select enough breeding pairs from a population to create a
		new population of equal size, assuming one child per couple.&quot;&quot;&quot;</span>
		bp = <span style="color: black;">&#91;</span><span style="color: black;">&#93;</span>
		pop_size = <span style="color: #008000;">len</span><span style="color: black;">&#40;</span><span style="color: #008000;">self</span>._population<span style="color: black;">&#41;</span>
&nbsp;
		<span style="color: #ff7700;font-weight:bold;">for</span> i <span style="color: #ff7700;font-weight:bold;">in</span> <span style="color: #008000;">range</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">0</span>, pop_size<span style="color: black;">&#41;</span>:
			mom = <span style="color: #008000;">self</span>._natural_select<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
			dad = <span style="color: #008000;">self</span>._natural_select<span style="color: black;">&#40;</span><span style="color: black;">&#91;</span>mom<span style="color: black;">&#93;</span><span style="color: black;">&#41;</span>
			bp.<span style="color: black;">append</span><span style="color: black;">&#40;</span><span style="color: black;">&#40;</span>mom,dad<span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>
&nbsp;
		<span style="color: #ff7700;font-weight:bold;">return</span> bp
&nbsp;
	<span style="color: #ff7700;font-weight:bold;">def</span> _breed_new_generation<span style="color: black;">&#40;</span><span style="color: #008000;">self</span>, mirror<span style="color: black;">&#41;</span>:
		<span style="color: #483d8b;">&quot;&quot;&quot;Create a new generation, breeding it from the older
		generation using natural selection.&quot;&quot;&quot;</span>
		new_gen = <span style="color: black;">&#91;</span><span style="color: black;">&#93;</span>
		bp = <span style="color: #008000;">self</span>._breeding_pairs<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
		<span style="color: #ff7700;font-weight:bold;">for</span> mom,dad <span style="color: #ff7700;font-weight:bold;">in</span> bp:
			kid = Individual.<span style="color: black;">breed</span><span style="color: black;">&#40;</span>mirror, mom,dad<span style="color: black;">&#41;</span>
			new_gen.<span style="color: black;">append</span><span style="color: black;">&#40;</span>kid<span style="color: black;">&#41;</span>
&nbsp;
		<span style="color: #008000;">self</span>.<span style="color: black;">sacrifice_count</span> += <span style="color: #008000;">len</span><span style="color: black;">&#40;</span><span style="color: #008000;">self</span>._population<span style="color: black;">&#41;</span>
		<span style="color: #008000;">self</span>._population = new_gen
&nbsp;
	<span style="color: #ff7700;font-weight:bold;">def</span> _analyse_population<span style="color: black;">&#40;</span><span style="color: #008000;">self</span><span style="color: black;">&#41;</span>:
		<span style="color: #483d8b;">&quot;&quot;&quot;Evaluate the genetic fitness of the entire population.&quot;&quot;&quot;</span>
		<span style="color: #ff7700;font-weight:bold;">for</span> i <span style="color: #ff7700;font-weight:bold;">in</span> <span style="color: #008000;">self</span>._population:
			i.<span style="color: black;">self_evaluate</span><span style="color: black;">&#40;</span><span style="color: #008000;">self</span>._mirror<span style="color: black;">&#41;</span>
&nbsp;
		<span style="color: #008000;">self</span>._population.<span style="color: black;">sort</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
		most_civilised = <span style="color: #008000;">self</span>._population<span style="color: black;">&#91;</span><span style="color: #ff4500;">0</span><span style="color: black;">&#93;</span>
&nbsp;
		<span style="color: #ff7700;font-weight:bold;">return</span> most_civilised
&nbsp;
	<span style="color: #ff7700;font-weight:bold;">def</span> evolve_civilisation<span style="color: black;">&#40;</span><span style="color: #008000;">self</span><span style="color: black;">&#41;</span>:
		<span style="color: #483d8b;">&quot;&quot;&quot;Evolve this civilisation until the required fitness_level
		is reached.&quot;&quot;&quot;</span>
		generation_count = <span style="color: #ff4500;">1</span>
		last_str_len = <span style="color: #ff4500;">0</span>
		<span style="color: #ff7700;font-weight:bold;">while</span><span style="color: black;">&#40;</span>generation_count<span style="color: black;">&#41;</span>:
			most_civilised = <span style="color: #008000;">self</span>._analyse_population<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
			gen_ord = ordinal<span style="color: black;">&#40;</span>generation_count + <span style="color: #ff4500;">1</span><span style="color: black;">&#41;</span>
&nbsp;
			<span style="color: #ff7700;font-weight:bold;">if</span> most_civilised.<span style="color: black;">fitness</span> <span style="color: #66cc66;">&gt;</span>= <span style="color: #008000;">self</span>._fitness_required:
				<span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">&quot;Evolved to %3.0f%% perfection. Concluding.&quot;</span> <span style="color: #66cc66;">%</span> most_civilised.<span style="color: black;">fitness</span>
				<span style="color: #ff7700;font-weight:bold;">return</span> most_civilised
			<span style="color: #ff7700;font-weight:bold;">else</span>:
				<span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">&quot;%s (perfection: %3.0f%%) Evolving % 10s generation.&quot;</span> <span style="color: #66cc66;">%</span> <span style="color: black;">&#40;</span>most_civilised._genes, most_civilised.<span style="color: black;">fitness</span>, gen_ord<span style="color: black;">&#41;</span>
				<span style="color: #008000;">self</span>._breed_new_generation<span style="color: black;">&#40;</span><span style="color: #008000;">self</span>._mirror<span style="color: black;">&#41;</span>
&nbsp;
			generation_count += <span style="color: #ff4500;">1</span>
&nbsp;
<span style="color: #808080; font-style: italic;"># a couple of helper functions #############</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">def</span> ordinal<span style="color: black;">&#40;</span>n<span style="color: black;">&#41;</span>:
	<span style="color: #483d8b;">&quot;&quot;&quot;borrowed from John Machin's python-list post.  Appends an
	ordinal suffix to a number.  For example, 1 becomes 1st,
	2 becomes 2nd, etc.&quot;&quot;&quot;</span>
	<span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: #ff4500;">10</span> <span style="color: #66cc66;">&lt;</span>= n <span style="color: #66cc66;">%</span> <span style="color: #ff4500;">100</span> <span style="color: #66cc66;">&lt;</span> <span style="color: #ff4500;">20</span>:
		<span style="color: #ff7700;font-weight:bold;">return</span> <span style="color: #008000;">str</span><span style="color: black;">&#40;</span>n<span style="color: black;">&#41;</span> + <span style="color: #483d8b;">'th'</span>
	<span style="color: #ff7700;font-weight:bold;">else</span>:
		<span style="color: #ff7700;font-weight:bold;">return</span>  <span style="color: #008000;">str</span><span style="color: black;">&#40;</span>n<span style="color: black;">&#41;</span> + <span style="color: black;">&#123;</span><span style="color: #ff4500;">1</span> : <span style="color: #483d8b;">'st'</span>, <span style="color: #ff4500;">2</span> : <span style="color: #483d8b;">'nd'</span>, <span style="color: #ff4500;">3</span> : <span style="color: #483d8b;">'rd'</span><span style="color: black;">&#125;</span>.<span style="color: black;">get</span><span style="color: black;">&#40;</span>n <span style="color: #66cc66;">%</span> <span style="color: #ff4500;">10</span>, <span style="color: #483d8b;">&quot;th&quot;</span><span style="color: black;">&#41;</span>
&nbsp;
&nbsp;
<span style="color: #ff7700;font-weight:bold;">def</span> PrintLargeNumber<span style="color: black;">&#40;</span>n,width=<span style="color: #ff4500;">2</span>,delim=<span style="color: #483d8b;">','</span>,<span style="color: #dc143c;">decimal</span>=<span style="color: #483d8b;">'.'</span><span style="color: black;">&#41;</span>:
	<span style="color: #483d8b;">&quot;&quot;&quot;Converts a float to a string with appropriately placed commas.
&nbsp;
	Floats will be shown with 'width' digits right of the decimal.
	'delim' specifies the thousands delimiter.
	'decimal' specifies the decimal character.
&nbsp;
	Copyright 2007 Regents of the University of California
	Written by David Isaacson at the University of California,
	Davis BSD License&quot;&quot;&quot;</span>
	<span style="color: #ff7700;font-weight:bold;">if</span> width <span style="color: #66cc66;">&gt;</span>= <span style="color: #ff4500;">0</span>: s = <span style="color: #483d8b;">&quot;%.*f&quot;</span> <span style="color: #66cc66;">%</span><span style="color: black;">&#40;</span>width,n<span style="color: black;">&#41;</span>
	<span style="color: #ff7700;font-weight:bold;">else</span>: s = <span style="color: #008000;">str</span><span style="color: black;">&#40;</span>n<span style="color: black;">&#41;</span>
	dec = s.<span style="color: black;">find</span><span style="color: black;">&#40;</span><span style="color: #dc143c;">decimal</span><span style="color: black;">&#41;</span>
	<span style="color: #ff7700;font-weight:bold;">if</span> dec == -<span style="color: #ff4500;">1</span>: dec = <span style="color: #008000;">len</span><span style="color: black;">&#40;</span>s<span style="color: black;">&#41;</span>
	threes = <span style="color: #008000;">int</span><span style="color: black;">&#40;</span><span style="color: black;">&#40;</span>dec-<span style="color: #ff4500;">1</span><span style="color: black;">&#41;</span>/<span style="color: #ff4500;">3</span><span style="color: black;">&#41;</span> <span style="color: #808080; font-style: italic;"># we don't need a comma at the start</span>
	<span style="color: #ff7700;font-weight:bold;">for</span> i <span style="color: #ff7700;font-weight:bold;">in</span> <span style="color: #008000;">xrange</span><span style="color: black;">&#40;</span>threes<span style="color: black;">&#41;</span>:
		loc = dec-<span style="color: #ff4500;">3</span><span style="color: #66cc66;">*</span><span style="color: black;">&#40;</span>i+<span style="color: #ff4500;">1</span><span style="color: black;">&#41;</span>
		s = s<span style="color: black;">&#91;</span>:loc<span style="color: black;">&#93;</span> + delim + s<span style="color: black;">&#91;</span>loc:<span style="color: black;">&#93;</span>
	<span style="color: #ff7700;font-weight:bold;">return</span> s
&nbsp;
<span style="color: #808080; font-style: italic;">############################################</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">def</span> evolve_from_nothingness<span style="color: black;">&#40;</span>msg<span style="color: black;">&#41;</span>:
	<span style="color: #483d8b;">&quot;&quot;&quot;Evolve an individual capable of saying the given msg.&quot;&quot;&quot;</span>
	world = World<span style="color: black;">&#40;</span>Mirror<span style="color: black;">&#40;</span>msg<span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>
	greeter = world.<span style="color: black;">evolve_civilisation</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
&nbsp;
	large_num_str = PrintLargeNumber<span style="color: black;">&#40;</span>world.<span style="color: black;">sacrifice_count</span>, width=<span style="color: #ff4500;">0</span><span style="color: black;">&#41;</span>
&nbsp;
	<span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>%s individuals sacrificed their lives<span style="color: #000099; font-weight: bold;">\n</span>so that their species could eventually say:<span style="color: #000099; font-weight: bold;">\n</span><span style="color: #000099; font-weight: bold;">\n</span><span style="color: #000099; font-weight: bold;">\t</span>%s<span style="color: #000099; font-weight: bold;">\n</span><span style="color: #000099; font-weight: bold;">\n</span>&quot;</span> <span style="color: #66cc66;">%</span> <span style="color: black;">&#40;</span>large_num_str, greeter._genes<span style="color: black;">&#41;</span>
&nbsp;
&nbsp;
<span style="color: #ff7700;font-weight:bold;">if</span> __name__ == <span style="color: #483d8b;">&quot;__main__&quot;</span>:
	evolve_from_nothingness<span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;Hello, Lifeforms!&quot;</span><span style="color: black;">&#41;</span>
&nbsp;
	<span style="color: #dc143c;">sys</span>.<span style="color: black;">stdout</span>.<span style="color: black;">write</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;Press return: &quot;</span><span style="color: black;">&#41;</span>
	<span style="color: #dc143c;">sys</span>.<span style="color: black;">stdout</span>.<span style="color: black;">flush</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
	<span style="color: #dc143c;">sys</span>.<span style="color: black;">stdin</span>.<span style="color: #dc143c;">readline</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span></pre></div></div>

<p>All in all, it&#8217;s pretty sweet.  It evolves fairly constantly, straight to the answer, in less than 40 generations.  Completes in a few seconds as well.</p>
<p>I&#8217;ve no doubt the SF Bay guys would find problems with this.  They&#8217;re into pointlessly obfuscated code, FP, and lambdas, for instance.  I&#8217;m into pointedly unobfuscated code, and using FP only when it makes things much clearer.  And optimisation is for compilers long after your algorithms and portability have done their thing.  That said, most of this IS off the top of my head, and I&#8217;m sure there are better ways to do it, so let me know if there are obvious (or not so obvious) improvements that can be made.</p>
<p>Anyway&#8230; for me, this is what programming&#8217;s all about.  In what other fields can you create worlds, create lifeforms, prove that evolution works, test yourself, frustrate yourself, and enjoy seeing your project finally work, all in the space of a few hours?</p>
<p>I should probably thank the python guys for a lot of that rapid development; the C++ version took much longer.  Then again, it had a virtual CPU and datatyped I/O etc.  I think it was threaded, too, if I remember correctly.  It also took hours to work out that the way to get 4 out of two 2s was to add them.  I might try that again someday, with a tweaked CPU/instruction set/program model.</p>
]]></content:encoded>
			<wfw:commentRss>http://irukado.org/2009/07/12/hello-lifeforms/feed</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Turbogears 2.0 released</title>
		<link>http://irukado.org/2009/05/27/turbogears-20-released</link>
		<comments>http://irukado.org/2009/05/27/turbogears-20-released#comments</comments>
		<pubDate>Wed, 27 May 2009 22:12:58 +0000</pubDate>
		<dc:creator>Lee</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[FOSS]]></category>
		<category><![CDATA[IT]]></category>
		<category><![CDATA[django]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[turbogears]]></category>
		<category><![CDATA[web]]></category>

		<guid isPermaLink="false">http://irukado.org/?p=1444</guid>
		<description><![CDATA[Turbogears 2.0 has finally been released!.  Read the TG2 release announcement, the changelog, or just dive in with the tutorials.
I&#8217;ve been holding off on playing with TG2 too much, since it wasn&#8217;t final, but now I&#8217;m gonna have a good play.  It&#8217;ll be interesting to compare this with django, cherrypy 3, etc.
]]></description>
			<content:encoded><![CDATA[<p><a href="http://turbogears.org/2.0/">Turbogears 2.0 has finally been released!</a>.  Read the <a href="http://compoundthinking.com/blog/index.php/2009/05/27/639/">TG2 release announcement</a>, the <a href="http://trac.turbogears.org/wiki/2.0/changelog">changelog</a>, or just dive in with the <a href="http://www.turbogears.org/2.0/docs/main/Wiki20/wiki20.html">tutorials</a>.</p>
<p>I&#8217;ve been holding off on playing with TG2 too much, since it wasn&#8217;t final, but now I&#8217;m gonna have a good play.  It&#8217;ll be interesting to compare this with django, cherrypy 3, etc.</p>
]]></content:encoded>
			<wfw:commentRss>http://irukado.org/2009/05/27/turbogears-20-released/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Mathemagical</title>
		<link>http://irukado.org/2009/03/16/mathemagical</link>
		<comments>http://irukado.org/2009/03/16/mathemagical#comments</comments>
		<pubDate>Mon, 16 Mar 2009 22:20:04 +0000</pubDate>
		<dc:creator>Lee</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[IT]]></category>
		<category><![CDATA[Journal]]></category>
		<category><![CDATA[django]]></category>
		<category><![CDATA[math]]></category>
		<category><![CDATA[python]]></category>

		<guid isPermaLink="false">http://irukado.org/?p=1246</guid>
		<description><![CDATA[I&#8217;ve been slowly upgrading my understanding of complex math lately, by working (in python) through stuff on Project Euler and betterexplained, etc.  I just discovered the derivations package in Debian.  It&#8217;s a book of applied math proofs, styled after K&#038;R&#8217;s The C Programming Language&#8217;s logical progression and easy reference (K&#038;R&#8217;s TCPL is a [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been slowly upgrading my understanding of complex math lately, by working (in python) through stuff on <a href="http://projecteuler.net/">Project Euler</a> and <a href="http://www.betterexplained.com/">betterexplained</a>, etc.  I just discovered <a href="http://packages.debian.org/unstable/doc/derivations">the derivations package</a> in <a href="http://www.debian.org/">Debian</a>.  It&#8217;s a book of applied math proofs, styled after K&#038;R&#8217;s The C Programming Language&#8217;s logical progression and easy reference (K&#038;R&#8217;s TCPL is a book that I really enjoyed, and it opened a lot of (conceptual) doors for me as a kid).</p>
<p>Working through this in python is a very useful exercise; it&#8217;s teaching me lots about the most efficient ways of doing things in that language, and with the standard library tools, some of which I rarely find use for otherwise.</p>
<p>Anyway, together with some other things mentioned in the preface, Derivations seems like a very promising book.  Except for one thing:</p>
<blockquote type="cite"><p>One particular respect in which the book departs requires some defense here, I think: the book employs hexadecimal numerals.</p></blockquote>
<p>So it&#8217;s going to explain complex math, but it&#8217;s going to do it&#8230; in hexadecimal.</p>
<p>Not sure whether to laugh or cry.  But I&#8217;ll see how it goes.  I don&#8217;t entirely disagree with the idea that, &#8220;If one wishes to reach hexadecimal ground, one must leap.&#8221;  It&#8217;s just that I don&#8217;t really see the point of becoming THAT fluent in hex, when understanding the basic concept of bases, and knowing how to convert from dec<>hex<>oct<>bin, that 2<sup>5</sup> is 32, and that 2<sup>32</sup> is roughly ~4 billion is almost certainly enough.  Is this book really suggesting I learn to do all my math in hex?  And if so, is there any real benefit?  It does seem to suggest that math is more beautiful in hex, but I&#8217;ve never heard of anything special about base-16, in relation to laws of physics, for instance.</p>
<p>Well, find out next time, same bat-time, same bat-channel, I guess <img src='http://irukado.org/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://irukado.org/2009/03/16/mathemagical/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Cute!</title>
		<link>http://irukado.org/2009/03/14/cute</link>
		<comments>http://irukado.org/2009/03/14/cute#comments</comments>
		<pubDate>Sat, 14 Mar 2009 09:03:14 +0000</pubDate>
		<dc:creator>Lee</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[FOSS]]></category>
		<category><![CDATA[IT]]></category>
		<category><![CDATA[amiga]]></category>
		<category><![CDATA[animation]]></category>
		<category><![CDATA[graphics]]></category>
		<category><![CDATA[kde]]></category>
		<category><![CDATA[kinetic]]></category>
		<category><![CDATA[performance]]></category>
		<category><![CDATA[qt]]></category>
		<category><![CDATA[rendering]]></category>

		<guid isPermaLink="false">http://irukado.org/?p=1241</guid>
		<description><![CDATA[Hmm.  Qt&#8217;s kinetic is pretty cool.  Of course, Amigas could easily do something very similar back in the 80&#8217;s (with BOBs), but it&#8217;s a big step forward for more &#8220;modern&#8221; systems  
]]></description>
			<content:encoded><![CDATA[<p>Hmm.  <a href="http://labs.trolltech.com/blogs/2009/03/04/animated-tiles/">Qt&#8217;s kinetic is pretty cool</a>.  Of course, Amigas could easily do something very similar back in the 80&#8217;s (with BOBs), but it&#8217;s a big step forward for more &#8220;modern&#8221; systems <img src='http://irukado.org/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://irukado.org/2009/03/14/cute/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Django Development: Runserver Ideal vs. Deployment Reality</title>
		<link>http://irukado.org/2009/03/12/django-development-runserver-ideal-vs-deployment-reality</link>
		<comments>http://irukado.org/2009/03/12/django-development-runserver-ideal-vs-deployment-reality#comments</comments>
		<pubDate>Thu, 12 Mar 2009 16:44:46 +0000</pubDate>
		<dc:creator>Lee</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[FOSS]]></category>
		<category><![CDATA[IT]]></category>
		<category><![CDATA[apache]]></category>
		<category><![CDATA[dependencies]]></category>
		<category><![CDATA[deployment]]></category>
		<category><![CDATA[django]]></category>
		<category><![CDATA[errors]]></category>
		<category><![CDATA[middleware]]></category>
		<category><![CDATA[modwsgi]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[oracle]]></category>
		<category><![CDATA[ordering]]></category>
		<category><![CDATA[postgresql]]></category>
		<category><![CDATA[priorities]]></category>
		<category><![CDATA[pylons]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[sqlite]]></category>
		<category><![CDATA[syncdb]]></category>
		<category><![CDATA[turbogears]]></category>

		<guid isPermaLink="false">http://irukado.org/?p=1232</guid>
		<description><![CDATA[This is going to be a slightly cheesed off post.  Better skip it if you&#8217;re not thick-skinned.  Back to happier django posts soon&#8230; if I can forgive this.
So I&#8217;m deploying my first real django app to a live server, with modwsgi.  ModWSGI itself isn&#8217;t great, as it insists on a single python [...]]]></description>
			<content:encoded><![CDATA[<p>This is going to be a slightly cheesed off post.  Better skip it if you&#8217;re not thick-skinned.  Back to happier django posts soon&#8230; <em>if</em> I can forgive this.</p>
<p>So I&#8217;m deploying my first real django app to a live server, with modwsgi.  ModWSGI itself isn&#8217;t great, as it insists on a single python version per apache server (and a global WSGIPythonHome rather than per vhost), thereby negating most of the benefits of virtualenv [update: seems I can use site.addsitedir() to get around this].  But my real problem with this deployment has not been modwsgi &#8212; that&#8217;s the nice, smooth part.</p>
<h2>MySQL table name length limits</h2>
<p>The problem is that django behaves entirely differently when deployed under modwsgi from testing under runserver(_plus).</p>
<p>First off, I did the obvious: copy the site over to the server, and change the database config from a local SQLite file (used for development) to a MySQL database on the live server.  The next step is to run:</p>
<blockquote><p><code>./manage.py syncdb</code></p></blockquote>
<p>to initialise the database tables.  This led to the first problem, which was a <em>huge</em> one.  Django creates table names that are too long for MySQL (the limit is 64 characters, I believe) &#8212; the most common open source DB around!  As a result, it simply doesn&#8217;t work with that database backend:</p>
<blockquote><p><code>File "/var/lib/python-support/python2.6/django/core/management/commands/syncdb.py", line 80, in handle_noargs<br />
    cursor.execute(statement)<br />
  File "/var/lib/python-support/python2.6/django/db/backends/util.py", line 19, in execute<br />
    return self.cursor.execute(sql, params)<br />
  File "/var/lib/python-support/python2.6/django/db/backends/mysql/base.py", line 83, in execute<br />
    return self.cursor.execute(query, args)<br />
  File "/var/lib/python-support/python2.6/MySQLdb/cursors.py", line 166, in execute<br />
    self.errorhandler(self, exc, value)<br />
  File "/var/lib/python-support/python2.6/MySQLdb/connections.py", line 35, in defaulterrorhandler<br />
    raise errorclass, errorvalue<br />
_mysql_exceptions.OperationalError: (1059, "Identifier name 'preferred_beneficiary_id_refs_basebeneficiary_ptr_id_24644201ef7702ef' is too long")<br />
</code></p></blockquote>
<p>The only solution seems to be shortening the names of all your models, which is a bit useless after you&#8217;ve just completed testing your app and are ready to deploy it, or using another backend.  I&#8217;ve read that the problem also exists with PostgreSQL.  Surprisingly, it existed in Oracle too, much more severely, but that has been fixed:</p>
<blockquote><p><strong><a href="http://docs.djangoproject.com/en/dev/ref/databases/#naming-issues">Naming issues</a></strong></p>
<p>Oracle imposes a name length limit of 30 characters. To accommodate this, the backend truncates database identifiers to fit, replacing the final four characters of the truncated name with a repeatable MD5 hash value.</p>
</blockquote>
<p>I don&#8217;t have (or want) Oracle available of course, so that leaves a file-based backend for now, and re-naming lots of core models as soon as I get a bit of time.  Not fun.  A simple assertion check in the Django code against my model names while I developed the thing (or a few unit tests by Django developers) would have saved me all this deployment hassle.</p>
<p>But that&#8217;s just the start of the trouble, it seems.</p>
<h2>Middleware ordering</h2>
<p>I&#8217;m also seeing lots of problems related to middleware and and (probably) to their load-order.  Lovely errors like &#8220;ModWSGIRequest.user is not defined&#8221;, which is pretty fundamental to Django, considering that just about every view uses the .user attribute from its first request argument, and that every template in a dynamic app that depends on the logged-in user also depends on it.</p>
<p>All of that would be fine, if it was my mistake.  The thing that gets me is, this load-order stuff was almost entirely copied from django&#8217;s (and satchmo&#8217;s) examples, and worked fine in the development test server.  If anything, I&#8217;d expect the test server (especially with debugging enabled) to be the more fussy target.</p>
<p>I&#8217;m still getting to the bottom of all this, and I&#8217;m not optimistic about solving it soon, since, as others have pointed out, <a href="http://www.toofishes.net/blog/django-middleware-order/">There is no canonical reference for django middleware order</a>, even though the docs often warn that it&#8217;s very important.  Different examples give different orders (or say things like &#8220;must be last&#8221;, despite other middleware having the same vague requirement).</p>
<p>Then there are lovely issues with satchmo.  Satchmo is a whole other beast though, so I won&#8217;t get into those right now.</p>
<p>Suffice to say, deploying django after developing is <strong>not at all</strong> a straightforward matter of uploading code and initialising or updating the live database.  If I ever develop with django again, I&#8217;ll almost certainly use a development server with a setup identical to the live one.  Runserver just doesn&#8217;t cut it.  In reality, I&#8217;m very much thinking of Pylons or Turbogears for future projects.</p>
]]></content:encoded>
			<wfw:commentRss>http://irukado.org/2009/03/12/django-development-runserver-ideal-vs-deployment-reality/feed</wfw:commentRss>
		<slash:comments>21</slash:comments>
		</item>
		<item>
		<title>Python 3.1 alpha 1 released</title>
		<link>http://irukado.org/2009/03/08/python-31-alpha-1-released</link>
		<comments>http://irukado.org/2009/03/08/python-31-alpha-1-released#comments</comments>
		<pubDate>Sun, 08 Mar 2009 12:57:48 +0000</pubDate>
		<dc:creator>Lee</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[FOSS]]></category>
		<category><![CDATA[class hierarchies]]></category>
		<category><![CDATA[inheritance]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[python]]></category>

		<guid isPermaLink="false">http://irukado.org/?p=1216</guid>
		<description><![CDATA[It seems that Python 3.1 alpha 1 has been released already.  A quick scan of the NEWS file reveals some nice performance improvements in there:

IO stuff reimplemented in C
new garbage collector
faster Unicode handling
computed gotos (which I&#8217;ve never heard of, but apparently offers 20% speedup on supported compilers)

Things like this keep shocking me in python&#8217;s [...]]]></description>
			<content:encoded><![CDATA[<p>It seems that <a href="http://www.python.org/download/releases/3.1/">Python 3.1 alpha 1</a> has been released already.  A quick scan of the <a href="http://www.python.org/download/releases/3.1/NEWS.txt">NEWS file</a> reveals some nice performance improvements in there:</p>
<ul>
<li>IO stuff reimplemented in C</li>
<li>new garbage collector</li>
<li>faster Unicode handling</li>
<li>computed gotos (which I&#8217;ve never heard of, but apparently offers 20% speedup on supported compilers)</li>
</ul>
<p>Things like this keep shocking me in python&#8217;s release notes though:</p>
<blockquote><p><code>- Issue #4707: round(x, n) now returns an integer if x is an integer.<br />
  Previously it returned a float.</code></p></blockquote>
<p>and from <a href="http://www.python.org/download/releases/3.0.1/NEWS.txt">Python 3.0.1&#8217;s NEWS</a>:</p>
<blockquote><p><code>- Issue #4998: Decimal no longer subclasses from or is registered to<br />
numbers.Real.  Instead, it is registered to numbers.Number so that<br />
isinstance(d, Number) will work.</code></p></blockquote>
<p>In a release of the C standard library or something, changes like that would mean API and ABI breakage.  With python&#8217;s flexible typing, it&#8217;s not so much of an issue, I guess.  Still, it would be nice if someone had sat down and thought about the math a bit more, and been sure about what was right from the beginning.  Working out if Decimals should be Real numbers (or, indeed, if Reals should be Numbers) shouldn&#8217;t be this hard, should it?</p>
<p>Hmm.  I was sure Java would have gotten this right, but it seems not:</p>
<blockquote><p><code>class java.lang.Number<br />
* class java.lang.Double<br />
* class java.lang.Float<br />
* class java.lang.Integer<br />
* class java.lang.Long</code></p></blockquote>
<p>So longs aren&#8217;t integers, and Floats and Doubles are unrelated, except for being some kind of Number?  Oh well.  It&#8217;s not like math is important in computer science, right? <img src='http://irukado.org/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<p>Anyway.  I&#8217;m trying to keep track of Python 3.x, but until a lot more libraries are available that run with it, it&#8217;s mostly a far off dream.  Shame, as I&#8217;ve been dying to dump 2.x in favor of the new Unicode stuff <img src='http://irukado.org/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://irukado.org/2009/03/08/python-31-alpha-1-released/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
