<?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>xchmp &#187; Software</title>
	<atom:link href="http://xchmp.com/category/software/feed/" rel="self" type="application/rss+xml" />
	<link>http://xchmp.com</link>
	<description></description>
	<lastBuildDate>Mon, 15 Feb 2010 11:34:14 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Hello Gene</title>
		<link>http://xchmp.com/2009/02/hello-gene/</link>
		<comments>http://xchmp.com/2009/02/hello-gene/#comments</comments>
		<pubDate>Mon, 02 Feb 2009 22:44:08 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Software]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[genetic programming]]></category>

		<guid isPermaLink="false">http://xchmp.com/?p=114</guid>
		<description><![CDATA[While on breaks at work I&#8217;ve been reading a bit about Genetic Programming. The following is a quick-and-dirty python script I threw together (mostly for myself) the other night. It evolves the target string &#8220;Hello World&#8221; over several generations, starting with random strings. After a bit of experimentation I found that a population size of [...]]]></description>
			<content:encoded><![CDATA[<p>While on breaks at work I&#8217;ve been reading a bit about <a href="http://en.wikipedia.org/wiki/Genetic_programming">Genetic Programming</a>. The following is a quick-and-dirty python script I threw together (mostly for myself) the other night. It evolves the target string &#8220;Hello World&#8221; over several generations, starting with random strings. After a bit of experimentation I found that a population size of 300 seems to work best for this.</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">random</span>
<span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">string</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">class</span> GenePool:
    <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>, population_size<span style="color: black;">&#41;</span>:
        <span style="color: #008000;">self</span>.<span style="color: black;">population_size</span> = population_size
        <span style="color: #008000;">self</span>.<span style="color: black;">population</span> = <span style="color: black;">&#91;</span><span style="color: #008000;">self</span>.<span style="color: black;">generate</span><span style="color: black;">&#40;</span><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>population_size<span style="color: black;">&#41;</span><span style="color: black;">&#93;</span>
&nbsp;
    <span style="color: #ff7700;font-weight:bold;">def</span> run<span style="color: black;">&#40;</span><span style="color: #008000;">self</span><span style="color: black;">&#41;</span>:
        i = <span style="color: #ff4500;">0</span>
        <span style="color: #ff7700;font-weight:bold;">while</span> <span style="color: #008000;">True</span>:
            <span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">&quot;Generation &quot;</span> + <span style="color: #008000;">str</span><span style="color: black;">&#40;</span>i<span style="color: black;">&#41;</span> + <span style="color: #483d8b;">&quot;: &quot;</span> + <span style="color: #008000;">self</span>.<span style="color: black;">population</span><span style="color: black;">&#91;</span><span style="color: #ff4500;">0</span><span style="color: black;">&#93;</span>
            i = i + <span style="color: #ff4500;">1</span>
            <span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: #008000;">self</span>.<span style="color: black;">step</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>:
                <span style="color: #ff7700;font-weight:bold;">return</span>
&nbsp;
&nbsp;
    <span style="color: #ff7700;font-weight:bold;">def</span> step<span style="color: black;">&#40;</span><span style="color: #008000;">self</span><span style="color: black;">&#41;</span>:
        fittest = <span style="color: #008000;">self</span>.<span style="color: black;">get_best</span><span style="color: black;">&#40;</span><span style="color: #008000;">self</span>.<span style="color: black;">population_size</span>/<span style="color: #ff4500;">2</span><span style="color: black;">&#41;</span>
        <span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: #008000;">self</span>.<span style="color: black;">successful</span><span style="color: black;">&#40;</span>fittest<span style="color: black;">&#91;</span><span style="color: #ff4500;">0</span><span style="color: black;">&#93;</span><span style="color: black;">&#41;</span>:
            <span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">&quot;Success! &quot;</span> + fittest<span style="color: black;">&#91;</span><span style="color: #ff4500;">0</span><span style="color: black;">&#93;</span>
            <span style="color: #ff7700;font-weight:bold;">return</span> <span style="color: #008000;">True</span>
        <span style="color: #ff7700;font-weight:bold;">else</span>:
            <span style="color: #008000;">self</span>.<span style="color: black;">population</span> = <span style="color: #008000;">self</span>.<span style="color: black;">get_new_generation</span><span style="color: black;">&#40;</span>fittest<span style="color: black;">&#41;</span>
            <span style="color: #ff7700;font-weight:bold;">return</span> <span style="color: #008000;">False</span>
&nbsp;
    <span style="color: #ff7700;font-weight:bold;">def</span> generate<span style="color: black;">&#40;</span><span style="color: #008000;">self</span><span style="color: black;">&#41;</span>:
        <span style="color: #ff7700;font-weight:bold;">return</span> <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: #dc143c;">random</span>.<span style="color: black;">choice</span><span style="color: black;">&#40;</span><span style="color: #dc143c;">string</span>.<span style="color: black;">ascii_letters</span> + <span style="color: #483d8b;">&quot; &quot;</span><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;">11</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> evaluate<span style="color: black;">&#40;</span><span style="color: #008000;">self</span>, individual<span style="color: black;">&#41;</span>:
        s = <span style="color: #483d8b;">&quot;Hello World&quot;</span>
        total = <span style="color: #ff4500;">0</span>
        <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: #008000;">len</span><span style="color: black;">&#40;</span>s<span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>:
            <span style="color: #ff7700;font-weight:bold;">if</span> individual<span style="color: black;">&#91;</span>idx<span style="color: black;">&#93;</span> == s<span style="color: black;">&#91;</span>idx<span style="color: black;">&#93;</span>:
                total = total + <span style="color: #ff4500;">1</span>
        <span style="color: #ff7700;font-weight:bold;">return</span> total / <span style="color: #ff4500;">11.0</span>
&nbsp;
    <span style="color: #ff7700;font-weight:bold;">def</span> get_best<span style="color: black;">&#40;</span><span style="color: #008000;">self</span>, n<span style="color: black;">&#41;</span>:
        fitness = <span style="color: black;">&#91;</span><span style="color: black;">&#93;</span>
        <span style="color: #ff7700;font-weight:bold;">for</span> idx, individual <span style="color: #ff7700;font-weight:bold;">in</span> <span style="color: #008000;">enumerate</span><span style="color: black;">&#40;</span><span style="color: #008000;">self</span>.<span style="color: black;">population</span><span style="color: black;">&#41;</span>:
            fitness.<span style="color: black;">append</span><span style="color: black;">&#40;</span><span style="color: black;">&#40;</span>idx, <span style="color: #008000;">self</span>.<span style="color: black;">evaluate</span><span style="color: black;">&#40;</span>individual<span style="color: black;">&#41;</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>
        fitness.<span style="color: black;">sort</span><span style="color: black;">&#40;</span><span style="color: #008000;">cmp</span>=<span style="color: #ff7700;font-weight:bold;">lambda</span> x,y: <span style="color: #008000;">cmp</span><span style="color: black;">&#40;</span>x<span style="color: black;">&#91;</span><span style="color: #ff4500;">1</span><span style="color: black;">&#93;</span>, y<span style="color: black;">&#91;</span><span style="color: #ff4500;">1</span><span style="color: black;">&#93;</span><span style="color: black;">&#41;</span>, reverse=<span style="color: #008000;">True</span><span style="color: black;">&#41;</span>
        best = <span style="color: black;">&#91;</span><span style="color: black;">&#93;</span>
        <span style="color: #ff7700;font-weight:bold;">return</span> <span style="color: black;">&#91;</span><span style="color: #008000;">self</span>.<span style="color: black;">population</span><span style="color: black;">&#91;</span>tup<span style="color: black;">&#91;</span><span style="color: #ff4500;">0</span><span style="color: black;">&#93;</span><span style="color: black;">&#93;</span> <span style="color: #ff7700;font-weight:bold;">for</span> tup <span style="color: #ff7700;font-weight:bold;">in</span> fitness<span style="color: black;">&#91;</span>:n<span style="color: black;">&#93;</span><span style="color: black;">&#93;</span>
&nbsp;
    <span style="color: #ff7700;font-weight:bold;">def</span> successful<span style="color: black;">&#40;</span><span style="color: #008000;">self</span>, individual<span style="color: black;">&#41;</span>:
        <span style="color: #ff7700;font-weight:bold;">return</span> individual == <span style="color: #483d8b;">&quot;Hello World&quot;</span>
&nbsp;
    <span style="color: #ff7700;font-weight:bold;">def</span> get_new_generation<span style="color: black;">&#40;</span><span style="color: #008000;">self</span>, individuals<span style="color: black;">&#41;</span>:
        population = <span style="color: black;">&#91;</span><span style="color: black;">&#93;</span>
        <span style="color: #ff7700;font-weight:bold;">while</span> <span style="color: #008000;">len</span><span style="color: black;">&#40;</span>population<span style="color: black;">&#41;</span> <span style="color: #66cc66;">&lt;</span> <span style="color: #008000;">int</span><span style="color: black;">&#40;</span><span style="color: #008000;">self</span>.<span style="color: black;">population_size</span> <span style="color: #66cc66;">*</span> <span style="color: #ff4500;">0.75</span><span style="color: black;">&#41;</span>:
            population.<span style="color: black;">extend</span><span style="color: black;">&#40;</span><span style="color: #008000;">self</span>.<span style="color: black;">breed</span><span style="color: black;">&#40;</span>
                                    <span style="color: #dc143c;">random</span>.<span style="color: black;">choice</span><span style="color: black;">&#40;</span>individuals<span style="color: black;">&#41;</span>,
                                    <span style="color: #dc143c;">random</span>.<span style="color: black;">choice</span><span style="color: black;">&#40;</span>individuals<span style="color: black;">&#41;</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>
        <span style="color: #ff7700;font-weight:bold;">while</span> <span style="color: #008000;">len</span><span style="color: black;">&#40;</span>population<span style="color: black;">&#41;</span> <span style="color: #66cc66;">&lt;</span> <span style="color: #008000;">self</span>.<span style="color: black;">population_size</span>:
            population.<span style="color: black;">append</span><span style="color: black;">&#40;</span><span style="color: #008000;">self</span>.<span style="color: black;">generate</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>
        <span style="color: #ff7700;font-weight:bold;">return</span> population
&nbsp;
    <span style="color: #ff7700;font-weight:bold;">def</span> breed<span style="color: black;">&#40;</span><span style="color: #008000;">self</span>, mother, father<span style="color: black;">&#41;</span>:
        point1 = <span style="color: #dc143c;">random</span>.<span style="color: black;">randint</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>mother<span style="color: black;">&#41;</span>-<span style="color: #ff4500;">2</span><span style="color: black;">&#41;</span>
        point2 = <span style="color: #dc143c;">random</span>.<span style="color: black;">randint</span><span style="color: black;">&#40;</span>point1+<span style="color: #ff4500;">1</span>, <span style="color: #008000;">len</span><span style="color: black;">&#40;</span>mother<span style="color: black;">&#41;</span>-<span style="color: #ff4500;">1</span><span style="color: black;">&#41;</span>
        new1 = mother<span style="color: black;">&#91;</span>:point1<span style="color: black;">&#93;</span> + father<span style="color: black;">&#91;</span>point1:point2<span style="color: black;">&#93;</span> + mother<span style="color: black;">&#91;</span>point2:<span style="color: black;">&#93;</span>
        new2 = father<span style="color: black;">&#91;</span>:point1<span style="color: black;">&#93;</span> + mother<span style="color: black;">&#91;</span>point1:point2<span style="color: black;">&#93;</span> + father<span style="color: black;">&#91;</span>point2:<span style="color: black;">&#93;</span>
        <span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: #dc143c;">random</span>.<span style="color: #dc143c;">random</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span> <span style="color: #66cc66;">&lt;</span> <span style="color: #ff4500;">0.05</span>:
            new1 = <span style="color: #008000;">self</span>.<span style="color: black;">mutate</span><span style="color: black;">&#40;</span>new1<span style="color: black;">&#41;</span>
        <span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: #dc143c;">random</span>.<span style="color: #dc143c;">random</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span> <span style="color: #66cc66;">&lt;</span> <span style="color: #ff4500;">0.05</span>:
            new2 = <span style="color: #008000;">self</span>.<span style="color: black;">mutate</span><span style="color: black;">&#40;</span>new2<span style="color: black;">&#41;</span>
        <span style="color: #ff7700;font-weight:bold;">return</span> <span style="color: black;">&#40;</span>new1, new2<span style="color: black;">&#41;</span>
&nbsp;
    <span style="color: #ff7700;font-weight:bold;">def</span> mutate<span style="color: black;">&#40;</span><span style="color: #008000;">self</span>, individual<span style="color: black;">&#41;</span>:
        x = <span style="color: #008000;">list</span><span style="color: black;">&#40;</span>individual<span style="color: black;">&#41;</span>
        x<span style="color: black;">&#91;</span><span style="color: #dc143c;">random</span>.<span style="color: black;">randint</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>x<span style="color: black;">&#41;</span>-<span style="color: #ff4500;">1</span><span style="color: black;">&#41;</span><span style="color: black;">&#93;</span> = <span style="color: #dc143c;">random</span>.<span style="color: black;">choice</span><span style="color: black;">&#40;</span>
                                            <span style="color: #dc143c;">random</span>.<span style="color: black;">choice</span><span style="color: black;">&#40;</span>
                                              <span style="color: #dc143c;">string</span>.<span style="color: black;">asciiletters</span> + <span style="color: #483d8b;">&quot; &quot;</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>
        <span style="color: #ff7700;font-weight:bold;">return</span> <span style="color: #483d8b;">&quot;&quot;</span>.<span style="color: black;">join</span><span style="color: black;">&#40;</span>x<span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">if</span> __name__ == <span style="color: #483d8b;">&quot;__main__&quot;</span>:
    G = GenePool<span style="color: black;">&#40;</span><span style="color: #ff4500;">300</span><span style="color: black;">&#41;</span>
    G.<span style="color: black;">run</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span></pre></div></div>

</pre>
]]></content:encoded>
			<wfw:commentRss>http://xchmp.com/2009/02/hello-gene/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Learning Java: Monty Hall Simulation</title>
		<link>http://xchmp.com/2009/01/learning-java-monty-hall-simulation/</link>
		<comments>http://xchmp.com/2009/01/learning-java-monty-hall-simulation/#comments</comments>
		<pubDate>Wed, 14 Jan 2009 16:17:10 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[learning java]]></category>
		<category><![CDATA[monty hall]]></category>

		<guid isPermaLink="false">http://xchmp.com/?p=69</guid>
		<description><![CDATA[I&#8217;ve always found the Monty Hall problem kind of interesting. So I wrote a little Java program to demonstrate it. Here&#8217;s an example of the output: C:\Home\working\java\MontyHall>java -jar MontyHallTest.jar 10000 Sticking with the same box wins 3368 out of 10000, or 33.68% Switching boxes wins 6682 out of 10000, or 66.82% Downloads: montyhall.zip &#8211; source [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve always found the <a href="http://en.wikipedia.org/wiki/Monty_hall_problem">Monty Hall problem</a> kind of interesting. So I wrote a little Java program to demonstrate it. Here&#8217;s an example of the output:</p>
<pre>
C:\Home\working\java\MontyHall>java -jar MontyHallTest.jar 10000
Sticking with the same box wins 3368 out of 10000, or 33.68%
Switching boxes wins 6682 out of 10000, or 66.82%
</pre>
<p>Downloads:<br />
<a href='http://xchmp.com/wp-content/uploads/2009/01/montyhall.zip'>montyhall.zip</a> &#8211; source files.<br />
<a href='http://xchmp.com/wp-content/uploads/2009/01/montyhalltest.jar'>montyhalltest.jar</a> &#8211; java archive.</p>
]]></content:encoded>
			<wfw:commentRss>http://xchmp.com/2009/01/learning-java-monty-hall-simulation/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Learning Java: Guess The Number</title>
		<link>http://xchmp.com/2009/01/learning-java-guess-the-number/</link>
		<comments>http://xchmp.com/2009/01/learning-java-guess-the-number/#comments</comments>
		<pubDate>Tue, 13 Jan 2009 14:18:15 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[learning java]]></category>
		<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://xchmp.com/?p=67</guid>
		<description><![CDATA[I&#8217;ve just finished reading the section on Basic I/O on the Java essential classes trail. So I put together a little Guess-The-Number game. import java.io.*; import java.lang.Math.*; &#160; public class NumberGame &#123; private Console c; private int upperBound; private int lowerBound; &#160; public NumberGame&#40;&#41; &#123; c = System.console&#40;&#41;; if &#40;c == null&#41; &#123; System.err.println&#40;&#34;Unable to [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve just finished reading the section on <a href="http://java.sun.com/docs/books/tutorial/essential/io/index.html">Basic I/O</a> on the Java essential classes trail. So I put together a little Guess-The-Number game.</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.io.*</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.lang.Math.*</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> NumberGame <span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">private</span> Console c<span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000066; font-weight: bold;">int</span> upperBound<span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000066; font-weight: bold;">int</span> lowerBound<span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> NumberGame<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        c <span style="color: #339933;">=</span> <span style="color: #003399;">System</span>.<span style="color: #006633;">console</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>c <span style="color: #339933;">==</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #003399;">System</span>.<span style="color: #006633;">err</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Unable to aquire console. Exiting...&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #003399;">System</span>.<span style="color: #006633;">exit</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000066; font-weight: bold;">void</span> playGame<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        c.<span style="color: #006633;">format</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Welcome to the guess-the-number game!%n&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        c.<span style="color: #006633;">format</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Think of a number between 1 and 100 and I'll try to &quot;</span> <span style="color: #339933;">+</span>
                 <span style="color: #0000ff;">&quot;guess it!%n&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        upperBound <span style="color: #339933;">=</span> <span style="color: #cc66cc;">100</span><span style="color: #339933;">;</span>
        lowerBound <span style="color: #339933;">=</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span>
        <span style="color: #000066; font-weight: bold;">boolean</span> finished<span style="color: #339933;">;</span>
        <span style="color: #000000; font-weight: bold;">do</span> <span style="color: #009900;">&#123;</span>
            finished <span style="color: #339933;">=</span> makeGuess<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">while</span> <span style="color: #009900;">&#40;</span>finished <span style="color: #339933;">==</span> <span style="color: #000066; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        c.<span style="color: #006633;">format</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Thank you for playing!%n&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000066; font-weight: bold;">boolean</span> makeGuess<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>upperBound <span style="color: #339933;">==</span> lowerBound<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            makeAccusation<span style="color: #009900;">&#40;</span>upperBound<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #000066; font-weight: bold;">true</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
        <span style="color: #000000; font-weight: bold;">else</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #000066; font-weight: bold;">int</span> choice <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>upperBound <span style="color: #339933;">-</span> lowerBound<span style="color: #009900;">&#41;</span> <span style="color: #339933;">/</span> <span style="color: #cc66cc;">2</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> lowerBound<span style="color: #339933;">;</span>
            <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #003399;">Math</span>.<span style="color: #006633;">random</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&lt;</span> <span style="color: #cc66cc;">0.5</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                <span style="color: #000066; font-weight: bold;">boolean</span> answer <span style="color: #339933;">=</span> askYesOrNo<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span>.<span style="color: #006633;">format</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;%nIs your &quot;</span> <span style="color: #339933;">+</span>
                                   <span style="color: #0000ff;">&quot;number higher than %d? &quot;</span>, choice<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>answer<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                    lowerBound <span style="color: #339933;">=</span> choice <span style="color: #339933;">+</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span>
                <span style="color: #009900;">&#125;</span>
                <span style="color: #000000; font-weight: bold;">else</span> <span style="color: #009900;">&#123;</span>
                    upperBound <span style="color: #339933;">=</span> choice<span style="color: #339933;">;</span>
                <span style="color: #009900;">&#125;</span>
            <span style="color: #009900;">&#125;</span>
            <span style="color: #000000; font-weight: bold;">else</span> <span style="color: #009900;">&#123;</span>
                <span style="color: #000066; font-weight: bold;">boolean</span> answer <span style="color: #339933;">=</span> askYesOrNo<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span>.<span style="color: #006633;">format</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;%nIs your &quot;</span> <span style="color: #339933;">+</span>
                                   <span style="color: #0000ff;">&quot;number lower than %d? &quot;</span>, choice<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>answer<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                    upperBound <span style="color: #339933;">=</span> choice<span style="color: #339933;">;</span>
                <span style="color: #009900;">&#125;</span>
                <span style="color: #000000; font-weight: bold;">else</span> <span style="color: #009900;">&#123;</span>
                    lowerBound <span style="color: #339933;">=</span> choice <span style="color: #339933;">-</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span>
                <span style="color: #009900;">&#125;</span>
            <span style="color: #009900;">&#125;</span>
        <span style="color: #009900;">&#125;</span>
        <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #000066; font-weight: bold;">false</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000066; font-weight: bold;">boolean</span> askYesOrNo<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span> query<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000066; font-weight: bold;">int</span> answer <span style="color: #339933;">=</span> <span style="color: #339933;">-</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span>
        <span style="color: #003399;">String</span> result<span style="color: #339933;">;</span>
        <span style="color: #000066; font-weight: bold;">char</span> resultChar <span style="color: #339933;">=</span> <span style="color: #0000ff;">' '</span><span style="color: #339933;">;</span>
        <span style="color: #000000; font-weight: bold;">while</span> <span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            result <span style="color: #339933;">=</span> c.<span style="color: #006633;">readLine</span><span style="color: #009900;">&#40;</span>query<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>result <span style="color: #339933;">!=</span> <span style="color: #0000ff;">&quot;&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                result <span style="color: #339933;">=</span> result.<span style="color: #006633;">toLowerCase</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>result.<span style="color: #006633;">length</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&gt;</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                    resultChar <span style="color: #339933;">=</span> result.<span style="color: #006633;">charAt</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                    <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>resultChar <span style="color: #339933;">==</span> <span style="color: #0000ff;">'y'</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                        <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #000066; font-weight: bold;">true</span><span style="color: #339933;">;</span>
                    <span style="color: #009900;">&#125;</span>
                    <span style="color: #000000; font-weight: bold;">else</span> <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>resultChar <span style="color: #339933;">==</span> <span style="color: #0000ff;">'n'</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                        <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #000066; font-weight: bold;">false</span><span style="color: #339933;">;</span>
                    <span style="color: #009900;">&#125;</span>
                <span style="color: #009900;">&#125;</span>
            c.<span style="color: #006633;">format</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Please answer 'yes' or 'no'.%n&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span>
        <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000066; font-weight: bold;">void</span> makeAccusation<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span> accusation<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000066; font-weight: bold;">boolean</span> result <span style="color: #339933;">=</span> askYesOrNo<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span>.<span style="color: #006633;">format</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;%nIs your number %d? &quot;</span>,
                                                            accusation<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>result<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            c.<span style="color: #006633;">format</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Awesome!%n&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
        <span style="color: #000000; font-weight: bold;">else</span> <span style="color: #009900;">&#123;</span>
            c.<span style="color: #006633;">format</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;One of us is obviously confused.%n&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000066; font-weight: bold;">void</span> main<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> args<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        NumberGame ng <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> NumberGame<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        ng.<span style="color: #006633;">playGame</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://xchmp.com/2009/01/learning-java-guess-the-number/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Learning Java &#8211; Rot13</title>
		<link>http://xchmp.com/2009/01/learning-java-rot13/</link>
		<comments>http://xchmp.com/2009/01/learning-java-rot13/#comments</comments>
		<pubDate>Thu, 08 Jan 2009 22:21:34 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[learning java]]></category>
		<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://xchmp.com/?p=55</guid>
		<description><![CDATA[I&#8217;m planning to do a masters degree in computing in the next year or two. Most of the courses I&#8217;ve been looking at are built around Java, so I thought it would be a good idea to learn a bit now when I can relax and take my time. So I&#8217;ve been working through the [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m planning to do a masters degree in computing in the next year or two. Most of the courses I&#8217;ve been looking at are built around Java, so I thought it would be a good idea to learn a bit now when I can relax and take my time. So I&#8217;ve been working through <a href="http://java.sun.com/docs/books/tutorial/index.html">the tutorial</a> over the last few days. I&#8217;m done with the basics and will shortly be moving on to those essential java classes. So I&#8217;m at the point where I can write some little programs to test that I actually do know what&#8217;s going on. This fancy book learning is all very well, but I like to get my hands dirty with whatever I&#8217;m trying to understand, so I&#8217;ll be trying out my knowledge as I go along.</p>
<p>This first program is pretty damn simple. But it&#8217;s the first program I&#8217;ve ever written in Java, so I&#8217;m kind of proud of it. It&#8217;s an implementation of the <a href="http://en.wikipedia.org/wiki/Rot13">rot13 cipher</a>.:</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> Rot13 <span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000000; font-weight: bold;">final</span> <span style="color: #003399;">String</span> ALPHABET <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;abcdefghijklmnopqrstuvwxyz&quot;</span><span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000066; font-weight: bold;">char</span> rotateChar<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">char</span> c<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #003399;">Character</span>.<span style="color: #006633;">isLetter</span><span style="color: #009900;">&#40;</span>c<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #000066; font-weight: bold;">int</span> idx <span style="color: #339933;">=</span> ALPHABET.<span style="color: #006633;">indexOf</span><span style="color: #009900;">&#40;</span><span style="color: #003399;">Character</span>.<span style="color: #006633;">toLowerCase</span><span style="color: #009900;">&#40;</span>c<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            idx <span style="color: #339933;">+=</span> <span style="color: #cc66cc;">13</span><span style="color: #339933;">;</span>
            <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>idx <span style="color: #339933;">&gt;=</span> <span style="color: #cc66cc;">26</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                idx <span style="color: #339933;">-=</span> <span style="color: #cc66cc;">26</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span>
            <span style="color: #000066; font-weight: bold;">char</span> rotatedChar <span style="color: #339933;">=</span> ALPHABET.<span style="color: #006633;">charAt</span><span style="color: #009900;">&#40;</span>idx<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #003399;">Character</span>.<span style="color: #006633;">isUpperCase</span><span style="color: #009900;">&#40;</span>c<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #003399;">Character</span>.<span style="color: #006633;">toUpperCase</span><span style="color: #009900;">&#40;</span>rotatedChar<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span>
            <span style="color: #000000; font-weight: bold;">else</span> <span style="color: #009900;">&#123;</span>
                <span style="color: #000000; font-weight: bold;">return</span> rotatedChar<span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span>
        <span style="color: #009900;">&#125;</span>
        <span style="color: #000000; font-weight: bold;">else</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #000000; font-weight: bold;">return</span> c<span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #003399;">String</span> rotate<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span> source<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000066; font-weight: bold;">char</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> resultArray <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #000066; font-weight: bold;">char</span><span style="color: #009900;">&#91;</span>source.<span style="color: #006633;">length</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
        <span style="color: #000000; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span> i <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span> i <span style="color: #339933;">&lt;</span> source.<span style="color: #006633;">length</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            resultArray<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> rotateChar<span style="color: #009900;">&#40;</span>source.<span style="color: #006633;">charAt</span><span style="color: #009900;">&#40;</span>i<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
        <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">String</span><span style="color: #009900;">&#40;</span>resultArray<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000066; font-weight: bold;">void</span> main<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> args<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span> i <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span> i <span style="color: #339933;">&lt;</span> args.<span style="color: #006633;">length</span><span style="color: #339933;">;</span> i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span>rotate<span style="color: #009900;">&#40;</span>args<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>This stuff is easier in Python, where I&#8217;d write something like:</p>
</pre>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">string</span>, <span style="color: #dc143c;">sys</span>
transtable = <span style="color: #dc143c;">string</span>.<span style="color: black;">maketrans</span><span style="color: black;">&#40;</span><span style="color: #dc143c;">string</span>.<span style="color: black;">ascii_letters</span>,
                 <span style="color: #dc143c;">string</span>.<span style="color: black;">ascii_lowercase</span><span style="color: black;">&#91;</span><span style="color: #ff4500;">13</span>:<span style="color: black;">&#93;</span> +
                 <span style="color: #dc143c;">string</span>.<span style="color: black;">ascii_lowercase</span><span style="color: black;">&#91;</span>:<span style="color: #ff4500;">13</span><span style="color: black;">&#93;</span> +
                 <span style="color: #dc143c;">string</span>.<span style="color: black;">ascii_uppercase</span><span style="color: black;">&#91;</span><span style="color: #ff4500;">13</span>:<span style="color: black;">&#93;</span> +
                 <span style="color: #dc143c;">string</span>.<span style="color: black;">ascii_uppercase</span><span style="color: black;">&#91;</span>:<span style="color: #ff4500;">13</span><span style="color: black;">&#93;</span><span style="color: black;">&#41;</span>
<span style="color: #ff7700;font-weight:bold;">for</span> arg <span style="color: #ff7700;font-weight:bold;">in</span> <span style="color: #dc143c;">sys</span>.<span style="color: black;">argv</span><span style="color: black;">&#91;</span><span style="color: #ff4500;">1</span>:<span style="color: black;">&#93;</span>:
    <span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #dc143c;">string</span>.<span style="color: black;">translate</span><span style="color: black;">&#40;</span>arg, transtable<span style="color: black;">&#41;</span></pre></div></div>

<p>Actually, I could write it on one line using less than 200 characters. Not that this is a good idea, but...</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">string</span> <span style="color: #ff7700;font-weight:bold;">as</span> s<span style="color: #66cc66;">;</span>import <span style="color: #dc143c;">sys</span><span style="color: #66cc66;">;</span>a=s.<span style="color: black;">ascii_lowercase</span><span style="color: #66cc66;">;</span>
b=s.<span style="color: black;">ascii_uppercase</span><span style="color: #66cc66;">;</span><span style="color: black;">&#91;</span><span style="color: #dc143c;">sys</span>.<span style="color: black;">stdout</span>.<span style="color: black;">write</span><span style="color: black;">&#40;</span>s.<span style="color: black;">translate</span><span style="color: black;">&#40;</span>
arg,s.<span style="color: black;">maketrans</span><span style="color: black;">&#40;</span>s.<span style="color: black;">ascii_letters</span>,a<span style="color: black;">&#91;</span><span style="color: #ff4500;">13</span>:<span style="color: black;">&#93;</span>+a<span style="color: black;">&#91;</span>:<span style="color: #ff4500;">13</span><span style="color: black;">&#93;</span>+
b<span style="color: black;">&#91;</span><span style="color: #ff4500;">13</span>:<span style="color: black;">&#93;</span>+b<span style="color: black;">&#91;</span>:<span style="color: #ff4500;">13</span><span style="color: black;">&#93;</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>+<span style="color: #483d8b;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: black;">&#41;</span> <span style="color: #ff7700;font-weight:bold;">for</span> arg <span style="color: #ff7700;font-weight:bold;">in</span> <span style="color: #dc143c;">sys</span>.<span style="color: black;">argv</span><span style="color: black;">&#91;</span><span style="color: #ff4500;">1</span>:<span style="color: black;">&#93;</span><span style="color: black;">&#93;</span></pre></div></div>

<p>So yeah, Java does seems a bit verbose at the moment.</p>
]]></content:encoded>
			<wfw:commentRss>http://xchmp.com/2009/01/learning-java-rot13/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>The Positivist Calendar</title>
		<link>http://xchmp.com/2008/12/the-positivist-calendar/</link>
		<comments>http://xchmp.com/2008/12/the-positivist-calendar/#comments</comments>
		<pubDate>Sat, 20 Dec 2008 13:05:49 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[History]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[auguste comte]]></category>
		<category><![CDATA[calendar]]></category>
		<category><![CDATA[positivism]]></category>
		<category><![CDATA[python]]></category>

		<guid isPermaLink="false">http://xchmp.com/?p=17</guid>
		<description><![CDATA[In 1849 Auguste Comte (1798-1857) published his &#8216;Calendrier positiviste&#8217;. This is not the place to expound Comte&#8217;s positivist philosophy, save to say that it encompassed lofty sentiments for the progress and betterment of the whole of mankind along rational lines. His calendar was intended as a vehicle for the inspiration of the people and to [...]]]></description>
			<content:encoded><![CDATA[<blockquote><p>In 1849 Auguste Comte (1798-1857) published his &#8216;Calendrier positiviste&#8217;. This is not the place to expound Comte&#8217;s positivist philosophy, save to say that it encompassed lofty sentiments for the progress and betterment of the whole of mankind along rational lines. His calendar was intended as a vehicle for the inspiration of the people and to be transparently simple. Formally it broke new ground by dividing the year into 13 months, each containing 28 days or four seven-day weeks; these accounted for 364 days. The remaining day (or two days in leap years) were complementary epagomenal days placed at the end of the year; they did not belong to any week, nor were assigned a weekday name.
</p></blockquote>
<p>&mdash; <em>Mapping Time: The Calendar and its History</em>, E.G. Richards</p>
<p>One of the nice things about the positivist calendar is that each day is dedicated to a particular person from history, ranging from Prometheus at the start of the year, all the way to Gall (a pioneer of neuroanatomy) at its end. This is also one of the reasons that few people other than Comte and his positivist friends took it seriously. Less fanciful attempts to reform the calendar have often failed, so Comte&#8217;s positivist calendar never stood a chance. These days it&#8217;s nothing more than an amusing historical footnote, which is a pity because even though it&#8217;s kind of ridiculous, it would be nice to live in a world where I could refer to today&#8217;s date as &#8220;Friday 19th Bichat, the day of Berthollet in the month of industry.&#8221; (That&#8217;s Marie Fran&ccedil;ois Xavier Bichat, an 18th Century French anatomist, and Claude Louis Berthollet, French chemist who helped devise modern chemical nomenclature.)</p>
<p>Obviously something had to be done. You can <a href="http://xchmp.com/poscal/poscal.py">view the positivist date here</a>. You can also <a href="http://xchmp.com/poscal/poscal.zip">download the source of the python script</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://xchmp.com/2008/12/the-positivist-calendar/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Retro Browser Games</title>
		<link>http://xchmp.com/2008/12/retro-browser-games/</link>
		<comments>http://xchmp.com/2008/12/retro-browser-games/#comments</comments>
		<pubDate>Tue, 09 Dec 2008 00:13:48 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Software]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[retro]]></category>

		<guid isPermaLink="false">http://xchmp.com/?p=5</guid>
		<description><![CDATA[Back in the day before all this modern flash and ajax stuff, we&#8217;d use javascript for our in-browser games. And we liked it. And we had to code using our teeth to press the keys on our keyboards because we couldn&#8217;t afford arms. Anyway, here&#8217;s a couple of slider games I made a long time [...]]]></description>
			<content:encoded><![CDATA[<p>Back in the day before all this modern flash and ajax stuff, we&#8217;d use javascript for our in-browser games. And we liked it. And we had to code using our teeth to press the keys on our keyboards because we couldn&#8217;t afford arms.</p>
<p>Anyway, <a href="http://xchmp.com/slider/slider2.html">here&#8217;s</a> a <a href="http://xchmp.com/slider/slider.html">couple</a> of slider games I made a long time ago, updated into modern javascript for your gaming pleasure. Go on &#8211; bask in the circa-1998 goodness.</p>
]]></content:encoded>
			<wfw:commentRss>http://xchmp.com/2008/12/retro-browser-games/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>One-dimensional cellular automata in javascript</title>
		<link>http://xchmp.com/2008/12/one-dimensional-cellular-automata-in-javascript/</link>
		<comments>http://xchmp.com/2008/12/one-dimensional-cellular-automata-in-javascript/#comments</comments>
		<pubDate>Tue, 09 Dec 2008 00:08:12 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Software]]></category>
		<category><![CDATA[cellular automata]]></category>
		<category><![CDATA[javascript]]></category>

		<guid isPermaLink="false">http://xchmp.com/?p=3</guid>
		<description><![CDATA[Here&#8216;s my implementation of a simple cellular automata generator that runs entirely in your browser. Won&#8217;t work in Internet Explorer. Definitely works in Firefox. (Modern versions of IE don&#8217;t support X-Bitmap images). It&#8217;s more a curiosity than anything else and it&#8217;s not going to win any prizes for speed, but it&#8217;s a good example of [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://xchmp.com/cellular/cellular.html">Here</a>&#8216;s my implementation of a simple <a href="http://en.wikipedia.org/wiki/Cellular_automata">cellular automata</a> generator that runs entirely in your browser. Won&#8217;t work in Internet Explorer. Definitely works in Firefox. (Modern versions of IE don&#8217;t support X-Bitmap images). It&#8217;s more a curiosity than anything else and it&#8217;s not going to win any prizes for speed, but it&#8217;s a good example of image generation using pure client-side javascript.</p>
]]></content:encoded>
			<wfw:commentRss>http://xchmp.com/2008/12/one-dimensional-cellular-automata-in-javascript/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
