<?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/"
	
	xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>Rough Book &#187; programming</title>
	<atom:link href="http://vivin.net/tag/programming/feed/" rel="self" type="application/rss+xml" />
	<link>http://vivin.net</link>
	<description>random musings of just another computer nerd</description>
	<lastBuildDate>Wed, 02 May 2012 18:20:05 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>Akṣi: Handwritten-digit-recognizing neural-network</title>
		<link>http://vivin.net/2011/11/24/ak%e1%b9%a3i-handwritten-digit-recognizing-neural-network/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=rss</link>
		<comments>http://vivin.net/2011/11/24/ak%e1%b9%a3i-handwritten-digit-recognizing-neural-network/#comments</comments>
		<pubDate>Thu, 24 Nov 2011 19:26:03 +0000</pubDate>
		<dc:creator>vivin</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[Programming and Development]]></category>
		<category><![CDATA[Science]]></category>
		<category><![CDATA[artificial intelligence]]></category>
		<category><![CDATA[machine-learning]]></category>
		<category><![CDATA[neural-networks]]></category>
		<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://vivin.net/?p=1803</guid>
		<description><![CDATA[I&#8217;ve always been interested in Neural Networks (ever since I first found out about them around 10 years ago). However, I never got a chance to learn about them or write one of my own; this is something I&#8217;ve wanted to do for some time. I got the opportunity this semester when my professor in [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve always been interested in Neural Networks (ever since I first found out about them around 10 years ago). However, I never got a chance to learn about them or write one of my own; this is something I&#8217;ve wanted to do for some time. I got the opportunity this semester when my professor in my advanced data-structures class told us that we could pick any topic we liked, for a semester project. I thought that this would be the perfect time for me to learn about neural networks and create one of my own.</p>
<p>The end result was <a href="http://aksi-neural-network.appspot.com/" title="Akṣi Handwritten-digit-recognizing neural-network" target="_blank">Akṣi</a>, a neural network that recognizes hand-written digits. I&#8217;ve hosted it using Google&#8217;s App Engine. Please check it out!</p>
<br /><a href="http://vivin.net/?p=1803#comments" title="Comments on &quot;Akṣi: Handwritten-digit-recognizing neural-network&quot;"><img src="http://vivin.net/wp-content/plugins/feed-comments-number/image.php?1803" alt="Comments" /></a><img src="http://vivin.net/?ak_action=api_record_view&#38;id=1803&#38;type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://vivin.net/2011/11/24/ak%e1%b9%a3i-handwritten-digit-recognizing-neural-network/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:thumbnail url="http://vivin.net/wp-content/plugins/feed-comments-number/image.php?1803" />
		<media:content url="http://vivin.net/wp-content/plugins/feed-comments-number/image.php?1803" medium="image">
			<media:title type="html">Comments</media:title>
		</media:content>
		<media:content url="http://vivin.net/?ak_action=api_record_view&#38;id=1803&#38;type=feed" medium="image" />
	</item>
		<item>
		<title>CherryBlossom</title>
		<link>http://vivin.net/2010/03/04/cherryblossom/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=rss</link>
		<comments>http://vivin.net/2010/03/04/cherryblossom/#comments</comments>
		<pubDate>Fri, 05 Mar 2010 02:58:26 +0000</pubDate>
		<dc:creator>vivin</dc:creator>
				<category><![CDATA[Arts]]></category>
		<category><![CDATA[Haiku]]></category>
		<category><![CDATA[Perl]]></category>
		<category><![CDATA[Poetry]]></category>
		<category><![CDATA[Programming and Development]]></category>
		<category><![CDATA[brainf*ck]]></category>
		<category><![CDATA[brainfuck]]></category>
		<category><![CDATA[cherryblossom]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[development]]></category>
		<category><![CDATA[esoteric languages]]></category>
		<category><![CDATA[haiku]]></category>
		<category><![CDATA[interpreters]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[parsers]]></category>
		<category><![CDATA[perl]]></category>
		<category><![CDATA[poems]]></category>
		<category><![CDATA[poetry]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[programming languages]]></category>
		<category><![CDATA[project]]></category>

		<guid isPermaLink="false">http://vivin.net/?p=1451</guid>
		<description><![CDATA[I&#8217;ve created a project page for the CherryBlossom programming language. You can check it out here. The interpreter is written in perl.]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve created a project page for the <em><strong>CherryBlossom</strong></em> programming language. You can check it out <a title = "CherryBlossom" href = "http://vivin.net/projects/cherryblossom" target="_self">here</a>. The interpreter is written in perl.</p>
<br /><a href="http://vivin.net/?p=1451#comments" title="Comments on &quot;CherryBlossom&quot;"><img src="http://vivin.net/wp-content/plugins/feed-comments-number/image.php?1451" alt="Comments" /></a><img src="http://vivin.net/?ak_action=api_record_view&#38;id=1451&#38;type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://vivin.net/2010/03/04/cherryblossom/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:thumbnail url="http://vivin.net/wp-content/plugins/feed-comments-number/image.php?1451" />
		<media:content url="http://vivin.net/wp-content/plugins/feed-comments-number/image.php?1451" medium="image">
			<media:title type="html">Comments</media:title>
		</media:content>
		<media:content url="http://vivin.net/?ak_action=api_record_view&#38;id=1451&#38;type=feed" medium="image" />
	</item>
		<item>
		<title>Introducing CherryBlossom</title>
		<link>http://vivin.net/2010/03/02/introducing-cherryblossom/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=rss</link>
		<comments>http://vivin.net/2010/03/02/introducing-cherryblossom/#comments</comments>
		<pubDate>Wed, 03 Mar 2010 06:06:49 +0000</pubDate>
		<dc:creator>vivin</dc:creator>
				<category><![CDATA[Arts]]></category>
		<category><![CDATA[Haiku]]></category>
		<category><![CDATA[Perl]]></category>
		<category><![CDATA[Poetry]]></category>
		<category><![CDATA[Programming and Development]]></category>
		<category><![CDATA[brainf*ck]]></category>
		<category><![CDATA[brainfuck]]></category>
		<category><![CDATA[cherryblossom]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[development]]></category>
		<category><![CDATA[esoteric languages]]></category>
		<category><![CDATA[haiku]]></category>
		<category><![CDATA[interpreters]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[parsers]]></category>
		<category><![CDATA[perl]]></category>
		<category><![CDATA[poems]]></category>
		<category><![CDATA[poetry]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[programming languages]]></category>
		<category><![CDATA[project]]></category>

		<guid isPermaLink="false">http://vivin.net/?p=1407</guid>
		<description><![CDATA[Over the past month, I&#8217;ve been working on a new project. It&#8217;s called CherryBlossom, and it&#8217;s a way to write programs using haikus. Strictly speaking, CherryBlossom is a brainfuck analog. I actually spent more time writing the obligatory &#8220;Hello World&#8221; program in CherryBlossom than I did writing the interpreter for the language. The idea behind [...]]]></description>
			<content:encoded><![CDATA[<p>Over the past month, I&#8217;ve been working on a new project. It&#8217;s called <strong><em><a href="http://vivin.net/projects/cherryblossom">CherryBlossom</a></em></strong>, and it&#8217;s a way to write programs using <a href="http://en.wikipedia.org/wiki/Haiku">haikus</a>. Strictly speaking, <strong><em>CherryBlossom</em></strong> is a brainfuck analog. I actually spent more time writing the obligatory &#8220;Hello World&#8221; program in CherryBlossom than I did writing the interpreter for the language. The idea behind <strong><em>CherryBlossom</em></strong> is simple. Brainfuck instructions are mapped to words that convey the essence of the Brainfuck instruction. Of course, this is a little subjective and also a little abstract. </p>
<p>Ultimately, it serves as a way to make program code not just functional, but beautiful and artistic. Thus, we introduce a new criteria to programming. Your code must not only be elegant algorithmically, but must also be poetic and artistic (also, since program code consists of haikus, you need to represent your code in sets of 3 lines with the first and last lines having 5 syllables, and the second line 7. That is, conforming to haiku rules). <strong><em>CherryBlossom</em></strong> serves to blend the programmer and the poet into one entity (hopefully with amazing results).</p>
<p>Here is an example of &#8220;Hello World!&#8221; in<strong> <em>CherryBlossom</em></strong>. I have opted to use a spruced up div tag instead of enclosing my beautiful poem in soulless <em>sourcecode</em> tags.<br />
<span id="more-1407"></span></p>
<div style = "margin-left:auto; margin-right:auto; text-align:center; background-image:url('/wordpress/wp-content/uploads/2010/03/cherryblossom25t.png'); background-repeat:no-repeat; width:350px; font-weight:bold; font-style:italic; font-size:12pt; font-family:times new roman;">
beautiful jasmine<br />
your lovely fragrance heals me<br />
every morning</p>
<p>remembering you,<br />
dreaming of your lovely smile,<br />
when will you come here?</p>
<p>floating butterflies<br />
sunshine and summer flowers<br />
a lovely morning</p>
<p>blossoming hillside<br />
on a fragrant summer day<br />
blooming, flowering.</p>
<p>I can remember<br />
my happy dreams of summer<br />
it was beautiful</p>
<p>flying doves, sunrays<br />
beauty flying in sunshine<br />
rain in the valley.</p>
<p>snow falls in moonlight,<br />
returns to the mountainside.<br />
lovely, beautiful.</p>
<p>view from mountaintop<br />
is a beautiful painting,<br />
in summer sunshine.</p>
<p>the fragrant flowers<br />
and the pretty butterflies<br />
spring by singing creek.</p>
<p>beautiful morning<br />
butterflies by riverside<br />
floating in sunshine.</p>
<p>such a lovely sight,<br />
the valley waterfall is<br />
in the spring sunshine.</p>
<p>sunrays and sunshine,<br />
the butterflies and flowers<br />
loving the new spring.</p>
<p>the pretty flowers<br />
are dreaming of a summer<br />
with the smiling sun.</p>
<p>music from heaven,<br />
is melodious and sweet,<br />
dreamy and happy.</p>
<p>the river is cold<br />
and misty in the moonlight,<br />
in the autumn chill.</p>
<p>winter riverside,<br />
lonely, icy, and chilly<br />
darkening evening</p>
<p>the lonely winter,<br />
barren riverside ahead<br />
a dreaming poet
</p></div>
<p>Trust me, this does print out &#8220;Hello World!&#8221;! You might think I&#8217;m crazy, but I&#8217;m not! Either tomorrow or day after, I&#8217;ll add a new page to the Projects menu and you&#8217;ll see how CherryBlossom works and you will also have access to the interpreter!</p>
<br /><a href="http://vivin.net/?p=1407#comments" title="Comments on &quot;Introducing CherryBlossom&quot;"><img src="http://vivin.net/wp-content/plugins/feed-comments-number/image.php?1407" alt="Comments" /></a><img src="http://vivin.net/?ak_action=api_record_view&#38;id=1407&#38;type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://vivin.net/2010/03/02/introducing-cherryblossom/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:thumbnail url="http://vivin.net/wp-content/plugins/feed-comments-number/image.php?1407" />
		<media:content url="http://vivin.net/wp-content/plugins/feed-comments-number/image.php?1407" medium="image">
			<media:title type="html">Comments</media:title>
		</media:content>
		<media:content url="http://vivin.net/?ak_action=api_record_view&#38;id=1407&#38;type=feed" medium="image" />
	</item>
		<item>
		<title>Maven project for Generic (n-ary) Tree in Java</title>
		<link>http://vivin.net/2010/03/02/maven-project-for-generic-n-ary-tree-in-java/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=rss</link>
		<comments>http://vivin.net/2010/03/02/maven-project-for-generic-n-ary-tree-in-java/#comments</comments>
		<pubDate>Wed, 03 Mar 2010 04:49:48 +0000</pubDate>
		<dc:creator>vivin</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[Programming and Development]]></category>
		<category><![CDATA[data structures]]></category>
		<category><![CDATA[generic trees]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[k-ary trees]]></category>
		<category><![CDATA[n-ary trees]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[software engineering]]></category>
		<category><![CDATA[trees (data structure)]]></category>

		<guid isPermaLink="false">http://vivin.net/?p=1405</guid>
		<description><![CDATA[Guus was kind enough to make a maven project for the Generic Tree. He also fixed an error in my equals method for the GenericTreeNode (I intended to do Object.equals(Object obj) but was doing GenericTreeNode.equals(GenericTreeNode obj). Since it&#8217;s a maven project, you can easily create a jar out of it and add it as a [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://vivin.net/2010/01/30/generic-n-ary-tree-in-java/#comment-1461">Guus</a> was kind enough to make a maven project for the Generic Tree. He also fixed an error in my <em>equals</em> method for the GenericTreeNode (I intended to do <em>Object.equals(Object obj)</em> but was doing <em>GenericTreeNode.equals(GenericTreeNode obj)</em>. Since it&#8217;s a maven project, you can easily create a <em>jar</em> out of it and add it as a dependency to your project. You can download the project <a href="https://github.com/vivin/GenericTree">here</a>. Thanks Guus!</p>
<br /><a href="http://vivin.net/?p=1405#comments" title="Comments on &quot;Maven project for Generic (n-ary) Tree in Java&quot;"><img src="http://vivin.net/wp-content/plugins/feed-comments-number/image.php?1405" alt="Comments" /></a><img src="http://vivin.net/?ak_action=api_record_view&#38;id=1405&#38;type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://vivin.net/2010/03/02/maven-project-for-generic-n-ary-tree-in-java/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
	
		<media:thumbnail url="http://vivin.net/wp-content/plugins/feed-comments-number/image.php?1405" />
		<media:content url="http://vivin.net/wp-content/plugins/feed-comments-number/image.php?1405" medium="image">
			<media:title type="html">Comments</media:title>
		</media:content>
		<media:content url="http://vivin.net/?ak_action=api_record_view&#38;id=1405&#38;type=feed" medium="image" />
	</item>
		<item>
		<title>Generic (n-ary) Tree in Java</title>
		<link>http://vivin.net/2010/01/30/generic-n-ary-tree-in-java/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=rss</link>
		<comments>http://vivin.net/2010/01/30/generic-n-ary-tree-in-java/#comments</comments>
		<pubDate>Sat, 30 Jan 2010 22:05:13 +0000</pubDate>
		<dc:creator>vivin</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[Programming and Development]]></category>
		<category><![CDATA[data structures]]></category>
		<category><![CDATA[generic trees]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[k-ary trees]]></category>
		<category><![CDATA[n-ary trees]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[software engineering]]></category>
		<category><![CDATA[trees (data structure)]]></category>

		<guid isPermaLink="false">http://vivin.net/?p=1395</guid>
		<description><![CDATA[This project is available on github. Please download from there to make sure you have the latest version. Last week I was solving a problem at work that required the use of a Generic (n-ary) Tree. An n-ary tree is a tree where node can have between 0 and n children. There is a special [...]]]></description>
			<content:encoded><![CDATA[<p><strong>This project is available on <a href="https://github.com/vivin/GenericTree">github</a>. Please download from there to make sure you have the latest version.</strong></p>
<p>Last week I was solving a problem at work that required the use of a Generic (<em>n</em>-ary) Tree. An <em>n</em>-ary tree is a tree where node can have between 0 and <em>n</em> children. There is a special case of <em>n</em>-ary trees where each node can have <em>at most</em> <em>n</em> nodes (<em>k</em>-ary tree). This implementation focuses on the most general case, where any node can have between 0 and <em>n</em> children. Java doesn&#8217;t have a Tree or Tree Node data structure. I couldn&#8217;t find any third-party implementations either (like in commons-lang). So I decided to write my own.<br />
<span id="more-1395"></span><br />
First, we need to define the node of our tree. Our node has two attributes. One is the data, and another is a List which can contain references to the children of that node:</p>
<div id="attachment_1397" class="wp-caption aligncenter" style="width: 310px;  border: 1px solid #dddddd; background-color: #f3f3f3; padding-top: 4px; margin: 10px; text-align:center; display: block; margin-right: auto; margin-left: auto;"><a href="http://vivin.net/wp-content/uploads/2010/01/generictreestructure.png"><img class="size-medium wp-image-1397" title="Generic Tree Node Structure" src="http://vivin.net/wp-content/uploads/2010/01/generictreestructure-300x167.png" alt="Structure of a Generic Tree Node" width="300" height="167" /></a><p style=' padding: 0 4px 5px; margin: 0;'  class="wp-caption-text">Structure of a Generic Tree Node</p></div>
<p>The code for a Generic Tree Node looks like this:</p>
<p><strong>GenericTreeNode.java</strong></p>
<pre class="brush: java">
import java.util.ArrayList;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class GenericTreeNode&lt;T&gt; {

    public T data;
    public List&lt;GenericTreeNode&lt;T&gt;&gt; children;

    public GenericTreeNode() {
        super();
        children = new ArrayList&lt;GenericTreeNode&lt;T&gt;&gt;();
    }

    public GenericTreeNode(T data) {
        this();
        setData(data);
    }

    public List&lt;GenericTreeNode&lt;T&gt;&gt; getChildren() {
        return this.children;
    }

    public int getNumberOfChildren() {
        return getChildren().size();
    }

    public boolean hasChildren() {
        return (getNumberOfChildren() &gt; 0);
    }

    public void setChildren(List&lt;GenericTreeNode&lt;T&gt;&gt; children) {
        this.children = children;
    }

    public void addChild(GenericTreeNode&lt;T&gt; child) {
        children.add(child);
    }

    public void addChildAt(int index, GenericTreeNode&lt;T&gt; child) throws IndexOutOfBoundsException {
        children.add(index, child);
    }

    public void removeChildren() {
        this.children = new ArrayList&lt;GenericTreeNode&lt;T&gt;&gt;();
    }

    public void removeChildAt(int index) throws IndexOutOfBoundsException {
        children.remove(index);
    }

    public GenericTreeNode&lt;T&gt; getChildAt(int index) throws IndexOutOfBoundsException {
        return children.get(index);
    }

    public T getData() {
        return this.data;
    }

    public void setData(T data) {
        this.data = data;
    }

    public String toString() {
        return getData().toString();
    }

    public boolean equals(GenericTreeNode&lt;T&gt; node) {
        return node.getData().equals(getData());
    }

    public int hashCode() {
        return getData().hashCode();
    }

    public String toStringVerbose() {
        String stringRepresentation = getData().toString() + &quot;:[&quot;;

        for (GenericTreeNode&lt;T&gt; node : getChildren()) {
            stringRepresentation += node.getData().toString() + &quot;, &quot;;
        }

        //Pattern.DOTALL causes ^ and $ to match. Otherwise it won&#039;t. It&#039;s retarded.
        Pattern pattern = Pattern.compile(&quot;, $&quot;, Pattern.DOTALL);
        Matcher matcher = pattern.matcher(stringRepresentation);

        stringRepresentation = matcher.replaceFirst(&quot;&quot;);
        stringRepresentation += &quot;]&quot;;

        return stringRepresentation;
    }
}
</pre>
<br /><a href="http://vivin.net/?p=1395#comments" title="Comments on &quot;Generic (n-ary) Tree in Java&quot;"><img src="http://vivin.net/wp-content/plugins/feed-comments-number/image.php?1395" alt="Comments" /></a><img src="http://vivin.net/?ak_action=api_record_view&#38;id=1395&#38;type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://vivin.net/2010/01/30/generic-n-ary-tree-in-java/feed/</wfw:commentRss>
		<slash:comments>37</slash:comments>
	
		<media:thumbnail url="http://vivin.net/wp-content/uploads/2010/01/generictreestructure-150x150.png" />
		<media:content url="http://vivin.net/wp-content/uploads/2010/01/generictreestructure.png" medium="image">
			<media:title type="html">Generic Tree Node Structure</media:title>
			<media:description type="html">Structure of a Generic Tree Node</media:description>
			<media:thumbnail url="http://vivin.net/wp-content/uploads/2010/01/generictreestructure-150x150.png" />
		</media:content>
		<media:content url="http://vivin.net/wp-content/plugins/feed-comments-number/image.php?1395" medium="image">
			<media:title type="html">Comments</media:title>
		</media:content>
		<media:content url="http://vivin.net/?ak_action=api_record_view&#38;id=1395&#38;type=feed" medium="image" />
	</item>
		<item>
		<title>A brainfuck interpreter in bAdkOde</title>
		<link>http://vivin.net/2010/01/23/a-brainfuck-interpreter-in-badkode/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=rss</link>
		<comments>http://vivin.net/2010/01/23/a-brainfuck-interpreter-in-badkode/#comments</comments>
		<pubDate>Sat, 23 Jan 2010 21:44:23 +0000</pubDate>
		<dc:creator>vivin</dc:creator>
				<category><![CDATA[Programming and Development]]></category>
		<category><![CDATA[Projects]]></category>
		<category><![CDATA[badkode]]></category>
		<category><![CDATA[brainf*ck]]></category>
		<category><![CDATA[brainfuck]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[computing]]></category>
		<category><![CDATA[development]]></category>
		<category><![CDATA[perl]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[programming languages]]></category>
		<category><![CDATA[project]]></category>
		<category><![CDATA[turing complete]]></category>
		<category><![CDATA[turing completeness]]></category>

		<guid isPermaLink="false">http://vivin.net/?p=1379</guid>
		<description><![CDATA[A few days before I left India, I started writing a brainfuck interpreter in bAdkOde. I finished implemented all the instructions, excepting for looping. I actually finished the code (and fixed all bugs) while I was in the air, flying from Dubai to Los Angeles. Emirates Airlines has power-plugs for your laptop on the seat. [...]]]></description>
			<content:encoded><![CDATA[<p>A few days before I left India, I started writing a <a href="http://www.muppetlabs.com/~breadbox/bf/">brainfuck</a> interpreter in <a href="http://vivin.net/projects/badkode/">bAdkOde</a>. I finished implemented all the instructions, excepting for looping. I actually finished the code (and fixed all bugs) while I was in the air, flying from Dubai to Los Angeles. Emirates Airlines has power-plugs for your laptop on the seat. It&#8217;s pretty sweet!</p>
<p>An interesting thing I noticed was that I couldn&#8217;t perfectly emulate the input instruction. I&#8217;m feeding the brainfuck code to the interpreter from STDIN and so that might be the problem. I&#8217;ve noticed that brainfuck interpreters written in brainfuck have the same problem. You have to specify program input before hand. This is what I&#8217;ve decided to do. You write brainfuck code, and then mark the end of program code by an exclamation mark. After the exclamation mark, you provide any input, and then mark the end of input by another exclamation mark. Programs that do not have any input end with two exclamation marks. After I finished writing the interpreter, I commented it. While I was doing this, I noticed a lack of labels in bAdkOde. So, I decided to update the interpreter to include them. Speaking of which, I really ought to rewrite the interpreter sometime&#8230;</p>
<p>Anyway, here is the code to the interpreter. I&#8217;m <a target="_blank" href="http://vivin.net/pub/bAdkOde/brainfuck_commented.bad">providing</a> a link to it, because the commented version is rather large. But here&#8217;s the expanded (without labels or macros), unformatted version:</p>
<pre class="brush: php">
&gt;3a&gt;1b{!b?b&gt;b[a)b-91b{=b+1[b&gt;1b}+91b-93b{=b-1[b&gt;1b}+93b(b+1a-33b}&gt;0[a+1a&gt;2b&gt;a[b&gt;1b{!b?b&gt;b[a+1a-33b}&gt;1b&gt;a[b&gt;0a&gt;[aa&gt;ab{=a&gt;1a&gt;[ab&gt;3a{![a)a&gt;[aa-62a{=a+1b-30000b)a&gt;ba{+b&gt;1b&gt;[bb)b&gt;0b-1b&gt;0a}{-a+30000b)b&gt;0a}(b(a+62a}+62a-60a{=a-1b)a&gt;1a&gt;[aa-ab&gt;ba{-b&gt;1a&gt;[aa+30000a&gt;ab)b&gt;0b&gt;0a-1a}{+a&gt;1a&gt;[aa+ab)b&gt;0a-1a}(b(a+60a}+60a-43a{=a+1[b+43a}+43a-45a{=a-1[b+45a}+45a-46a{=a&quot;[b+46a}+46a-44a{=a)a&gt;2a&gt;[aa&gt;[a[b&gt;2a+1[a(a+44a}+44a-91a{=a(a)b)a&gt;[bb{=b&gt;0b&gt;1[b{![b(a+1a)a&gt;[aa)a-91a{=a+1[a&gt;1a}+91a-93a{=a-1[a&gt;1a}+93a(a}(a-1a)a&gt;1b}(a(b)a+91a}+91a-93a{=a(a)b)a&gt;[bb{!b&gt;0b&gt;0[b-1[b{![b(a-1a)a&gt;[aa)a-91a{=a+1[a&gt;1a}+91a-93a{=a-1[a&gt;1a}+93a(a}&gt;0b}(a(b)a+93a}+93a(a+1a}&gt;1a&gt;0b}{!b&quot;85&quot;110&quot;109&quot;97&quot;116&quot;99&quot;104&quot;101&quot;100&quot;32&quot;98&quot;114&quot;97&quot;99&quot;107&quot;101&quot;116&quot;115&gt;0b}
</pre>
<p>Also, this is additional proof for Turing Completeness. Yes, I&#8217;m a nerd! <img src='http://vivin.net/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<br /><a href="http://vivin.net/?p=1379#comments" title="Comments on &quot;A brainfuck interpreter in bAdkOde&quot;"><img src="http://vivin.net/wp-content/plugins/feed-comments-number/image.php?1379" alt="Comments" /></a><img src="http://vivin.net/?ak_action=api_record_view&#38;id=1379&#38;type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://vivin.net/2010/01/23/a-brainfuck-interpreter-in-badkode/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
	
		<media:thumbnail url="http://vivin.net/wp-content/plugins/feed-comments-number/image.php?1379" />
		<media:content url="http://vivin.net/wp-content/plugins/feed-comments-number/image.php?1379" medium="image">
			<media:title type="html">Comments</media:title>
		</media:content>
		<media:content url="http://vivin.net/?ak_action=api_record_view&#38;id=1379&#38;type=feed" medium="image" />
	</item>
		<item>
		<title>bAdkOde is Turing Complete</title>
		<link>http://vivin.net/2009/12/26/badkode-is-turing-complete/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=rss</link>
		<comments>http://vivin.net/2009/12/26/badkode-is-turing-complete/#comments</comments>
		<pubDate>Sat, 26 Dec 2009 10:26:24 +0000</pubDate>
		<dc:creator>vivin</dc:creator>
				<category><![CDATA[Programming and Development]]></category>
		<category><![CDATA[Projects]]></category>
		<category><![CDATA[badkode]]></category>
		<category><![CDATA[brainf*ck]]></category>
		<category><![CDATA[brainfuck]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[computing]]></category>
		<category><![CDATA[development]]></category>
		<category><![CDATA[perl]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[programming languages]]></category>
		<category><![CDATA[project]]></category>
		<category><![CDATA[turing complete]]></category>
		<category><![CDATA[turing completeness]]></category>

		<guid isPermaLink="false">http://vivin.net/?p=1346</guid>
		<description><![CDATA[In my previous post, I suggested that bAdkOde might be Turing Complete by writing a quine. One of the ways to actually prove Turing Completeness is to try and write an interpreter for another Turing-Complete language in bAdkOde. Another approach involves providing a direct translation from another Turing-Complete language into bAdkOde. Here, I prove the [...]]]></description>
			<content:encoded><![CDATA[<p>In my <a href="http://vivin.net/2009/12/25/a-badkode-quine-which-suggests-that-badkode-is-turing-complete/">previous post</a>, I suggested that <a href="http://vivin.net/projects/badkode/">bAdkOde</a> might be <a href="http://en.wikipedia.org/wiki/Turing_complete">Turing Complete</a> by writing a <a href="http://en.wikipedia.org/wiki/Quine_(computing)">quine</a>. One of the ways to actually prove Turing Completeness is to try and write an interpreter for another Turing-Complete language in bAdkOde. Another approach involves providing a direct translation from another Turing-Complete language into bAdkOde. Here, I prove the Turing Completeness of bAdkOde by providing a direct translation from <a href="http://www.muppetlabs.com/~breadbox/bf/">Brainfuck</a> into bAdkOde.<br />
<span id="more-1346"></span><br />
<strong><u>Assumptions</u></strong></p>
<ol>
<li>The <em>a</em> register is our memory pointer.</li>
<li>We initialize the <em>a</em> register to 0.</li>
</ol>
<p><strong><u>Proof</u></strong></p>
<p>We translate Brainfuck to bAdkOde using the following mappings or rules:</p>
<ol>
<li><em>&gt;</em> maps to <em>+1a</em></li>
<li><em>&lt;</em> maps to <em>-1a</em></li>
<li><em>+</em> maps to <em>+1[a</em></li>
<li><em>-</em> maps to <em>-1[a</em></li>
<li><em>.</em> maps to <em>"[a</em></li>
<li><em>,</em> maps to <em>?[a</em></li>
<li><em>[</em> maps to <em>{![a</em></li>
<li><em>]</em> maps to <em>}</em></li>
</ol>
<p><strong><u>Conclusion</u></strong></p>
<p>Since we can completely translate or map Brainfuck, an already Turing-Complete language into bAdkOde, we can say that bAdkOde is also Turing Complete.</p>
<p><strong><u>Translated example</u></strong></p>
<p><strong>helloworld.bf:</strong></p>
<pre class="brush: php">
+++ +++ +++ +
[
    &gt; +++ +++ +
    &gt; +++ +++ +++ +
    &gt; +++
    &gt; +
    &lt;&lt;&lt; &lt; -
]
&gt;++ .
&gt;+.
+++ +++ +.
.
+++ .
&gt;++ .
&lt;&lt;+ +++ +++ +++ +++ ++.
&gt;.
+++ .
--- --- .
--- --- --.
&gt;+.
</pre>
<p><strong>helloworld.bad</strong></p>
<pre class="brush: php">
&gt;0a+1[a+1[a+1[a +1[a+1[a+1[a +1[a+1[a+1[a +1[a
{![a
    +1a +1[a+1[a+1[a +1[a+1[a+1[a +1[a
    +1a +1[a+1[a+1[a +1[a+1[a+1[a +1[a+1[a+1[a +1[a
    +1a +1[a+1[a+1[a
    +1a +1[a
    -1a-1a-1a -1a -1[a
}
+1a+1[a+1[a &quot;[a
+1a+1[a&quot;[a
+1[a+1[a+1[a +1[a+1[a+1[a +1[a&quot;[a
&quot;[a
+1[a+1[a+1[a &quot;[a
+1a+1[a+1[a &quot;[a
-1a-1a+1[a +1[a+1[a+1[a +1[a+1[a+1[a +1[a+1[a+1[a +1[a+1[a+1[a +1[a+1[a&quot;[a
+1a&quot;[a
+1[a+1[a+1[a &quot;[a
-1[a-1[a-1[a -1[a-1[a-1[a &quot;[a
-1[a-1[a-1[a -1[a-1[a-1[a -1[a-1[a&quot;[a
+1a+1[a&quot;[a
</pre>
<p>Here's a quick perl script that I whipped up, to translate Brainfuck to bAdkOde:</p>
<pre class="brush: perl">
#!/usr/bin/perl

 use strict;

 my $terminator = $/;
 undef $/;
 my $bf = &lt;STDIN&gt;;
 $bf =~ s/[^&lt;&gt;\[\]\.,\+\-\s\n]//g;
 $/ = $terminator;

 my $i = 0;

 print &quot;&gt;0a&quot;;

 while($i &lt; length($bf)) {

    my $bf_instruction = substr($bf, $i, 1);

    if($bf_instruction eq &#039;&gt;&#039;) {
       print &quot;+1a&quot;;
    }

    elsif($bf_instruction eq &#039;&lt;&#039;) {
       print &quot;-1a&quot;;
    }

    elsif($bf_instruction eq &#039;+&#039;) {
       print &quot;+1[a&quot;;
    }

    elsif($bf_instruction eq &#039;-&#039;) {
       print &quot;-1[a&quot;;
    }

    elsif($bf_instruction eq &#039;.&#039;) {
       print &quot;\&quot;[a&quot;;
    }

    elsif($bf_instruction eq &#039;,&#039;) {
       print &quot;?[a&quot;;
    }

    elsif($bf_instruction eq &#039;[&#039;) {
       print &quot;{![a&quot;;
    }

    elsif($bf_instruction eq &#039;]&#039;) {
       print &quot;}&quot;;
    }

    else {
       print $bf_instruction;
    }

    $i++;
 }
</pre>
<p><strong><u>Additional proof</u></strong></p>
<p>Since there exist self-interpreters for Brainfuck (i.e., Brainfuck interpreters written <em>in</em> Brainfuck), and since it has been shown that there exists a valid translation from Brainfuck to bAdkOde, it follows that it is possible to write a Brainfuck interpreter in bAdkOde. This provides additional proof for the Turing Completeness of bAdkOde.</p>
<br /><a href="http://vivin.net/?p=1346#comments" title="Comments on &quot;bAdkOde is Turing Complete&quot;"><img src="http://vivin.net/wp-content/plugins/feed-comments-number/image.php?1346" alt="Comments" /></a><img src="http://vivin.net/?ak_action=api_record_view&#38;id=1346&#38;type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://vivin.net/2009/12/26/badkode-is-turing-complete/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
	
		<media:thumbnail url="http://vivin.net/wp-content/plugins/feed-comments-number/image.php?1346" />
		<media:content url="http://vivin.net/wp-content/plugins/feed-comments-number/image.php?1346" medium="image">
			<media:title type="html">Comments</media:title>
		</media:content>
		<media:content url="http://vivin.net/?ak_action=api_record_view&#38;id=1346&#38;type=feed" medium="image" />
	</item>
		<item>
		<title>A bAdkOde quine (which suggests that bAdkOde is Turing Complete)</title>
		<link>http://vivin.net/2009/12/25/a-badkode-quine-which-suggests-that-badkode-is-turing-complete/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=rss</link>
		<comments>http://vivin.net/2009/12/25/a-badkode-quine-which-suggests-that-badkode-is-turing-complete/#comments</comments>
		<pubDate>Fri, 25 Dec 2009 11:12:41 +0000</pubDate>
		<dc:creator>vivin</dc:creator>
				<category><![CDATA[Programming and Development]]></category>
		<category><![CDATA[Projects]]></category>
		<category><![CDATA[badkode]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[computing]]></category>
		<category><![CDATA[development]]></category>
		<category><![CDATA[perl]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[programming languages]]></category>
		<category><![CDATA[project]]></category>
		<category><![CDATA[quine]]></category>
		<category><![CDATA[turing complete]]></category>
		<category><![CDATA[turing completeness]]></category>

		<guid isPermaLink="false">http://vivin.net/?p=1335</guid>
		<description><![CDATA[On the bAdkOde project page, I mentioned that I didn&#8217;t know whether bAdkOde is Turing Complete (although I suspected it). I also mentioned that if I was able to write a quine in bAdkOde, then it would probably mean that it is Turing Complete. I was able to write one after going through this excellent [...]]]></description>
			<content:encoded><![CDATA[<p>On the bAdkOde <a href="http://vivin.net/projects/badkode/">project page</a>, I mentioned that I didn&#8217;t know whether bAdkOde is <a href="http://en.wikipedia.org/wiki/Turing_completeness">Turing Complete</a> (although I suspected it). I also mentioned that if I was able to write a <a href="http://en.wikipedia.org/wiki/Quine_%28computing%29">quine</a> in bAdkOde, then it would probably mean that it is Turing Complete. I was able to write one after going through this <a href="http://dwcope.freeshell.org/projects/quine/">excellent quine tutorial</a> by Dave Cope.<br />
<span id="more-1335"></span><br />
A quine is basically a program that prints a copy of its source code. Writing a quine seems trivial, but can be, and is in most cases, fiendishly difficult. The quine tutorial that I mentioned earlier describes a rather simple method to create a quine. In any quine, you need to store a representation of part of the source code. This representation is referred to as the <strong>core</strong> or <strong>body</strong>. In the method described in the tutorial, and the method that I used, the core is represented as ASCII codes. In some approaches, the core is represented as a string or character array (which, when it comes down to it, is probably represented in memory as an array of ASCII codes). In the approach that I used, there are two parts to the core. The first part prints out the code for the data structure that will contain a representation of the core, and the second part prints out the actual core. For example, let&#8217;s say I wanted to make a Perl quine. I start off with the core:</p>
<pre class="brush: perl">
 print &quot; \@body = (\n&quot;;
 map { printf &quot;0x%x, &quot;, $_ } @body;
 print &quot; );\n&quot;;
 map { printf &quot;%c&quot;, $_ } @body;
</pre>
<p>Here, you can see that I&#8217;ve decided to use an array called <em>@body</em> to store the ASCII values (in hexadecimal). The first three lines print out the definition for the array that will hold the ASCII values. The last line reads the array, translates the code into actual characters, and prints them out. Now all we have to do is get the hexadecimal codes and create the array. To do that, we use a utility called <em>xxd</em>:</p>
<pre>
vivin@dauntless ~/Projects/code/perl/quine
$ xxd -i quinegen.pl >qhex.pl
</pre>
<p>The output is an array definition in C:</p>
<pre class="brush: c">
unsigned char quinegen_pl[] = {
  0x20, 0x70, 0x72, 0x69, 0x6e, 0x74, 0x20, 0x22, 0x20, 0x5c, 0x40, 0x62,
  0x6f, 0x64, 0x79, 0x20, 0x3d, 0x20, 0x28, 0x5c, 0x6e, 0x22, 0x3b, 0x0a,
  0x20, 0x6d, 0x61, 0x70, 0x20, 0x7b, 0x20, 0x70, 0x72, 0x69, 0x6e, 0x74,
  0x66, 0x20, 0x22, 0x30, 0x78, 0x25, 0x78, 0x2c, 0x20, 0x22, 0x2c, 0x20,
  0x24, 0x5f, 0x20, 0x7d, 0x20, 0x40, 0x62, 0x6f, 0x64, 0x79, 0x3b, 0x0a,
  0x20, 0x70, 0x72, 0x69, 0x6e, 0x74, 0x20, 0x22, 0x20, 0x29, 0x3b, 0x5c,
  0x6e, 0x22, 0x3b, 0x0a, 0x20, 0x6d, 0x61, 0x70, 0x20, 0x7b, 0x20, 0x70,
  0x72, 0x69, 0x6e, 0x74, 0x66, 0x20, 0x22, 0x25, 0x63, 0x22, 0x2c, 0x20,
  0x24, 0x5f, 0x20, 0x7d, 0x20, 0x40, 0x62, 0x6f, 0x64, 0x79, 0x3b, 0x0a
};
unsigned int quinegen_pl_len = 108;
</pre>
<p>We need to change this to valid Perl, and that&#8217;s quite simple:</p>
<pre class="brush: perl">
 @body = (
   0x20, 0x70, 0x72, 0x69, 0x6e, 0x74, 0x20, 0x22, 0x20, 0x5c, 0x40, 0x62,
   0x6f, 0x64, 0x79, 0x20, 0x3d, 0x20, 0x28, 0x5c, 0x6e, 0x22, 0x3b, 0x0a,
   0x20, 0x6d, 0x61, 0x70, 0x20, 0x7b, 0x20, 0x70, 0x72, 0x69, 0x6e, 0x74,
   0x66, 0x20, 0x22, 0x30, 0x78, 0x25, 0x78, 0x2c, 0x20, 0x22, 0x2c, 0x20,
   0x24, 0x5f, 0x20, 0x7d, 0x20, 0x40, 0x62, 0x6f, 0x64, 0x79, 0x3b, 0x0a,
   0x20, 0x70, 0x72, 0x69, 0x6e, 0x74, 0x20, 0x22, 0x20, 0x29, 0x3b, 0x5c,
   0x6e, 0x22, 0x3b, 0x0a, 0x20, 0x6d, 0x61, 0x70, 0x20, 0x7b, 0x20, 0x70,
   0x72, 0x69, 0x6e, 0x74, 0x66, 0x20, 0x22, 0x25, 0x63, 0x22, 0x2c, 0x20,
   0x24, 0x5f, 0x20, 0x7d, 0x20, 0x40, 0x62, 0x6f, 0x64, 0x79, 0x3b, 0x0a
 );
</pre>
<p>We take this and paste it on top of our core:</p>
<pre class="brush: perl">
 @body = (
   0x20, 0x70, 0x72, 0x69, 0x6e, 0x74, 0x20, 0x22, 0x20, 0x5c, 0x40, 0x62,
   0x6f, 0x64, 0x79, 0x20, 0x3d, 0x20, 0x28, 0x5c, 0x6e, 0x22, 0x3b, 0x0a,
   0x20, 0x6d, 0x61, 0x70, 0x20, 0x7b, 0x20, 0x70, 0x72, 0x69, 0x6e, 0x74,
   0x66, 0x20, 0x22, 0x30, 0x78, 0x25, 0x78, 0x2c, 0x20, 0x22, 0x2c, 0x20,
   0x24, 0x5f, 0x20, 0x7d, 0x20, 0x40, 0x62, 0x6f, 0x64, 0x79, 0x3b, 0x0a,
   0x20, 0x70, 0x72, 0x69, 0x6e, 0x74, 0x20, 0x22, 0x20, 0x29, 0x3b, 0x5c,
   0x6e, 0x22, 0x3b, 0x0a, 0x20, 0x6d, 0x61, 0x70, 0x20, 0x7b, 0x20, 0x70,
   0x72, 0x69, 0x6e, 0x74, 0x66, 0x20, 0x22, 0x25, 0x63, 0x22, 0x2c, 0x20,
   0x24, 0x5f, 0x20, 0x7d, 0x20, 0x40, 0x62, 0x6f, 0x64, 0x79, 0x3b, 0x0a
 );
 print &quot; \@body = (\n&quot;;
 map { printf &quot;0x%x, &quot;, $_ } @body;
 print &quot; );\n&quot;;
 map { printf &quot;%c&quot;, $_ } @body;
</pre>
<p>Now the interesting thing here is that this piece of code is not the actual quine. Rather, it <em>generates</em> the quine. But the generated code isn&#8217;t that different from the generator:</p>
<pre class="brush: perl">
 @body = (
0x20, 0x70, 0x72, 0x69, 0x6e, 0x74, 0x20, 0x22, 0x20, 0x5c, 0x40, 0x62, 0x6f, 0x64, 0x79, 0x20, 0x3d, 0x20, 0x28, 0x5c, 0x6e, 0x22, 0x3b, 0xa, 0x20, 0x6d, 0x61, 0x70, 0x20, 0x7b, 0x20, 0x70, 0x72, 0x69, 0x6e, 0x74, 0x66, 0x20, 0x22, 0x30, 0x78, 0x25, 0x78, 0x2c, 0x20, 0x22, 0x2c, 0x20, 0x24, 0x5f, 0x20, 0x7d, 0x20, 0x40, 0x62, 0x6f, 0x64, 0x79, 0x3b, 0xa, 0x20, 0x70, 0x72, 0x69, 0x6e, 0x74, 0x20, 0x22, 0x20, 0x29, 0x3b, 0x5c, 0x6e, 0x22, 0x3b, 0xa, 0x20, 0x6d, 0x61, 0x70, 0x20, 0x7b, 0x20, 0x70, 0x72, 0x69, 0x6e, 0x74, 0x66, 0x20, 0x22, 0x25, 0x63, 0x22, 0x2c, 0x20, 0x24, 0x5f, 0x20, 0x7d, 0x20, 0x40, 0x62, 0x6f, 0x64, 0x79, 0x3b, 0xa,  );
 print &quot; \@body = (\n&quot;;
 map { printf &quot;0x%x, &quot;, $_ } @body;
 print &quot; );\n&quot;;
 map { printf &quot;%c&quot;, $_ } @body;
</pre>
<p>The only difference is the extra comma in the array definition, and the fact that all the ASCII codes are on one line. If you run this perl script, you will get an exact copy of its source code. Now how do we write a quine in bAdkOde? We use a similar approach. First we write the core:</p>
<pre class="brush: php">
&gt;0a
&quot;62&quot;48&quot;97&quot;10
{![a
 &quot;62&#039;[a&quot;91&quot;97&quot;43&quot;49&quot;97
 +1a
}
&quot;10
&gt;0a
{![a
 &quot;[a
 +1a
}
</pre>
<p>To implement a quine in bAdkOde, I decided to store the representation of the core (in decimal ASCII values) in memory starting at location zero. The first line initializes the a register to zero. The second line prints out the string <em>>0a</em> with a newline. This line is analogous to the <em>print " \@body = (\n";</em> line in the perl quine. Within our first loop, we're printing out the actual code that will store the representation of the core in memory. So the first line within the loop prints <em>>ASCII[a+1a</em> where <em>ASCII</em> is the ASCII value of a character from the core. The line is analogous to the <em>printf "0x%x, ", $_</em> line in the perl quine. There is another print statement right outside the first loop, which simply prints a newline. This line is analogous to the <em>print " );\n";</em> line in the perl quine. The second loop performs the actual translation of the ASCII code into the core. Now, just like the perl quine, we use <em>xxd</em>:</p>
<pre>
vivin@dauntless ~/Projects/code/perl/bAdkOde
$ xxd -i quine.bad >qhex.txt
</pre>
<p>After doing this, we get C code that looks like this:</p>
<pre class="brush: c">
unsigned char quine_bad[] = {
  0x3e, 0x30, 0x61, 0x0a, 0x22, 0x36, 0x32, 0x22, 0x34, 0x38, 0x22, 0x39,
  0x37, 0x22, 0x31, 0x30, 0x0a, 0x7b, 0x21, 0x5b, 0x61, 0x0a, 0x20, 0x22,
  0x36, 0x32, 0x27, 0x5b, 0x61, 0x22, 0x39, 0x31, 0x22, 0x39, 0x37, 0x22,
  0x34, 0x33, 0x22, 0x34, 0x39, 0x22, 0x39, 0x37, 0x0a, 0x20, 0x2b, 0x31,
  0x61, 0x0a, 0x7d, 0x0a, 0x22, 0x31, 0x30, 0x0a, 0x3e, 0x30, 0x61, 0x0a,
  0x7b, 0x21, 0x5b, 0x61, 0x0a, 0x20, 0x22, 0x5b, 0x61, 0x0a, 0x20, 0x2b,
  0x31, 0x61, 0x0a, 0x7d, 0x0a
};
unsigned int quine_bad_len = 77;
</pre>
<p>Translating this into bAdkOde is not as straightforward, but it&#8217;s not that difficult either. I removed the first line, and the last two lines from <em>qhex.txt</em> and then used a oneliner:</p>
<pre>
vivin@dauntless ~/Projects/code/perl/bAdkOde
$ cat qhex.txt | perl -e 'chomp($a=&lt;STDIN&gt;); map { print ">" . hex($_) . "[a+1a"; } \
   split(",", $a);' > qdec.txt
</pre>
<p>You end up with this snippet of bAdkOde:</p>
<pre class="brush: php">
&gt;62[a+1a&gt;48[a+1a&gt;97[a+1a&gt;10[a+1a&gt;34[a+1a&gt;54[a+1a&gt;50[a+1a&gt;34[a+1a&gt;52[a+1a&gt;56[a+1a&gt;34[a+1a&gt;57[a+1a&gt;55[a+1a&gt;34[a+1a&gt;49[a+1a&gt;48[a+1a&gt;10[a+1a&gt;123[a+1a&gt;33[a+1a&gt;91[a+1a&gt;97[a+1a&gt;10[a+1a&gt;32[a+1a&gt;34[a+1a&gt;54[a+1a&gt;50[a+
1a&gt;39[a+1a&gt;91[a+1a&gt;97[a+1a&gt;34[a+1a&gt;57[a+1a&gt;49[a+1a&gt;34[a+1a&gt;57[a+1a&gt;55[a+1a&gt;34[a+1a&gt;52[a+1a&gt;51[a+1a&gt;34[a+1a&gt;52[a+1a&gt;57[a+1a&gt;34[a+1a&gt;57[a+1a&gt;55[a+1a&gt;10[a+1a&gt;32[a+1a&gt;43[a+1a&gt;49[a+1a&gt;97[a+1a&gt;10[a+1a&gt;125[a+1a&gt;10[
a+1a&gt;34[a+1a&gt;49[a+1a&gt;48[a+1a&gt;10[a+1a&gt;62[a+1a&gt;48[a+1a&gt;97[a+1a&gt;10[a+1a&gt;123[a+1a&gt;33[a+1a&gt;91[a+1a&gt;97[a+1a&gt;10[a+1a&gt;32[a+1a&gt;34[a+1a&gt;91[a+1a&gt;97[a+1a&gt;10[a+1a&gt;32[a+1a&gt;43[a+1a&gt;49[a+1a&gt;97[a+1a&gt;10[a+1a&gt;125[a+1a&gt;10[a+1a
</pre>
<p>Now all you need to do is copy this snippet into <em>quine.bad</em> (with one minor change) to get a bAdkOde quine:</p>
<pre class="brush: php">
&gt;0a
&gt;62[a+1a&gt;48[a+1a&gt;97[a+1a&gt;10[a+1a&gt;34[a+1a&gt;54[a+1a&gt;50[a+1a&gt;34[a+1a&gt;52[a+1a&gt;56[a+1a&gt;34[a+1a&gt;57[a+1a&gt;55[a+1a&gt;34[a+1a&gt;49[a+1a&gt;48[a+1a&gt;10[a+1a&gt;123[a+1a&gt;33[a+1a&gt;91[a+1a&gt;97[a+1a&gt;10[a+1a&gt;32[a+1a&gt;34[a+1a&gt;54[a+1a&gt;50[a+
1a&gt;39[a+1a&gt;91[a+1a&gt;97[a+1a&gt;34[a+1a&gt;57[a+1a&gt;49[a+1a&gt;34[a+1a&gt;57[a+1a&gt;55[a+1a&gt;34[a+1a&gt;52[a+1a&gt;51[a+1a&gt;34[a+1a&gt;52[a+1a&gt;57[a+1a&gt;34[a+1a&gt;57[a+1a&gt;55[a+1a&gt;10[a+1a&gt;32[a+1a&gt;43[a+1a&gt;49[a+1a&gt;97[a+1a&gt;10[a+1a&gt;125[a+1a&gt;10[
a+1a&gt;34[a+1a&gt;49[a+1a&gt;48[a+1a&gt;10[a+1a&gt;62[a+1a&gt;48[a+1a&gt;97[a+1a&gt;10[a+1a&gt;123[a+1a&gt;33[a+1a&gt;91[a+1a&gt;97[a+1a&gt;10[a+1a&gt;32[a+1a&gt;34[a+1a&gt;91[a+1a&gt;97[a+1a&gt;10[a+1a&gt;32[a+1a&gt;43[a+1a&gt;49[a+1a&gt;97[a+1a&gt;10[a+1a&gt;125[a+1a&gt;10[a+1a
&gt;0a
&quot;62&quot;48&quot;97&quot;10
{![a
 &quot;62&#039;[a&quot;91&quot;97&quot;43&quot;49&quot;97
 +1a
}
&quot;10
&gt;0a
{![a
 &quot;[a
 +1a
}
</pre>
<p>The small change I had to make, was to add <em>>0a</em> at the beginning. If you run this bAdkOde program, it will print its source code as output. So there you have it. A bAdkOde quine, which proves that bAdkOde is Turing Complete. I have to thank <a href="http://dwcope.freeshell.org/">Dave Cope</a> for his quine tutorial, without which it would have been extremely difficult for me to write a bAdkOde quine!</p>
<p><strong>Update (12/26/2009)</strong></p>
<p>Dave mentioned that writing a quine only <em>suggests</em> that a language is Turing Complete, but not that it is. He suggested that I write an interpreter for <a href = "http://www.muppetlabs.com/~breadbox/bf/">Brainfuck</a> which would then prove that bAdkOde is Turing Complete. That was actually my next project!</p>
<p><strong>Update (12/26/2009)</strong></p>
<p>I&#8217;ve been able to provide a <a href="http://vivin.net/2009/12/26/badkode-is-turing-complete/">direct translation</a> of Brainfuck into bAdkOde, which proves the Turing Completeness of bAdkOde.</p>
<br /><a href="http://vivin.net/?p=1335#comments" title="Comments on &quot;A bAdkOde quine (which suggests that bAdkOde is Turing Complete)&quot;"><img src="http://vivin.net/wp-content/plugins/feed-comments-number/image.php?1335" alt="Comments" /></a><img src="http://vivin.net/?ak_action=api_record_view&#38;id=1335&#38;type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://vivin.net/2009/12/25/a-badkode-quine-which-suggests-that-badkode-is-turing-complete/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:thumbnail url="http://vivin.net/wp-content/plugins/feed-comments-number/image.php?1335" />
		<media:content url="http://vivin.net/wp-content/plugins/feed-comments-number/image.php?1335" medium="image">
			<media:title type="html">Comments</media:title>
		</media:content>
		<media:content url="http://vivin.net/?ak_action=api_record_view&#38;id=1335&#38;type=feed" medium="image" />
	</item>
		<item>
		<title>if-else in bAdkOde</title>
		<link>http://vivin.net/2009/12/16/if-else-in-badkode/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=rss</link>
		<comments>http://vivin.net/2009/12/16/if-else-in-badkode/#comments</comments>
		<pubDate>Thu, 17 Dec 2009 02:11:27 +0000</pubDate>
		<dc:creator>vivin</dc:creator>
				<category><![CDATA[Programming and Development]]></category>
		<category><![CDATA[Projects]]></category>
		<category><![CDATA[assembly language]]></category>
		<category><![CDATA[badkode]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[development]]></category>
		<category><![CDATA[esoteric languages]]></category>
		<category><![CDATA[interpreters]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[logic]]></category>
		<category><![CDATA[parsers]]></category>
		<category><![CDATA[perl]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[programming languages]]></category>
		<category><![CDATA[project]]></category>

		<guid isPermaLink="false">http://vivin.net/?p=1321</guid>
		<description><![CDATA[I was talking to my CSE 200 (my first CS class at ASU) professor Richard Whitehouse about bAdkOde and he (rightly) pointed out that it didn&#8217;t have an explicit selection statement. He also said that unless I wanted it to be really ugly I&#8217;d need to have a selection statement. However, since I was going [...]]]></description>
			<content:encoded><![CDATA[<p>I was talking to my CSE 200 (my first CS class at ASU) professor Richard Whitehouse about <strong><a href="http://vivin.net/projects/badkode/">bAdkOde</a></strong> and he (rightly) pointed out that it didn&#8217;t have an explicit selection statement. He also said that unless I wanted it to be really ugly I&#8217;d need to have a selection statement. However, since I was going for ugly I figured that I&#8217;d just emulate the operation of an <em>if</em> and an <em>if-else</em> with the existing <em>while</em> statement.</p>
<p>If you know assembly, then you know that a <em>while</em> is simply a set of statements wrapped with a conditional branch at the top and a backwards branch at the bottom (or in other words, an <em>if</em> with a <em>goto</em> at the end. A <em>do-while</em> is simply a set of statements with a conditional branch (at the bottom) that branches to the top of the loop. In fact, in assembly programming there really aren&#8217;t any <em>for loops</em> or <em>while loops</em>. These keywords are simply abstractions and syntactic sugar. In <strong>bAdkOde</strong>, you can implement an <em>if</em> with the existing <em>while</em> statement if you explicitly make it break out of the loop. For example, let&#8217;s say that we want to check whether the user entered the character &#8220;0&#8243;:</p>
<pre class="brush: php">
?a
-48a
# print a line break
&quot;10
# if a is zero
{=a
 # print the string &quot;zero&quot;
 &quot;122&quot;101&quot;114&quot;111&quot;10
 # set the a register to a non-zero value so that we can break out of the loop
 &gt;1a
}
</pre>
<p>I knew there was a way to implement an <em>if-else</em> with just <em>while</em> statements but I didn&#8217;t remember exactly how. Then my friend and co-worker Juan reminded me that I needed two variables. In our case, we need to use two registers:</p>
<pre class="brush: php">
?a
-48a
# copy the value of a into b
&gt;ab
&quot;10
# if a is zero
{=a
 # print the string &quot;zero&quot;
 &quot;122&quot;101&quot;114&quot;111&quot;10
 # set the a register to a non-zero value so that we can break out of the loop
 &gt;1a
}
# if the top loop failed, it means that b (which holds the same value as a) is
# non-zero and so we can enter this block.
# if the top loop was successful, it means that b (which holds the same value
# as a) is zero and so we won&#039;t enter this block. Hence, the second block acts
# as an &#039;else&#039;
{!b
 # print the string &quot;non-zero&quot;
 &quot;110&quot;111&quot;110&quot;45&quot;122&quot;101&quot;114&quot;111&quot;10
 # zero out the b register
 &gt;0b
}
</pre>
<p>Yes, quite ugly. But that&#8217;s what I&#8217;m going for! <img src='http://vivin.net/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<br /><a href="http://vivin.net/?p=1321#comments" title="Comments on &quot;if-else in bAdkOde&quot;"><img src="http://vivin.net/wp-content/plugins/feed-comments-number/image.php?1321" alt="Comments" /></a><img src="http://vivin.net/?ak_action=api_record_view&#38;id=1321&#38;type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://vivin.net/2009/12/16/if-else-in-badkode/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:thumbnail url="http://vivin.net/wp-content/plugins/feed-comments-number/image.php?1321" />
		<media:content url="http://vivin.net/wp-content/plugins/feed-comments-number/image.php?1321" medium="image">
			<media:title type="html">Comments</media:title>
		</media:content>
		<media:content url="http://vivin.net/?ak_action=api_record_view&#38;id=1321&#38;type=feed" medium="image" />
	</item>
		<item>
		<title>bAdkOde: An Esoteric Language</title>
		<link>http://vivin.net/2009/12/13/badkode-an-esoteric-language/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=rss</link>
		<comments>http://vivin.net/2009/12/13/badkode-an-esoteric-language/#comments</comments>
		<pubDate>Mon, 14 Dec 2009 01:53:43 +0000</pubDate>
		<dc:creator>vivin</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[Perl]]></category>
		<category><![CDATA[Programming and Development]]></category>
		<category><![CDATA[Projects]]></category>
		<category><![CDATA[badkode]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[development]]></category>
		<category><![CDATA[esoteric languages]]></category>
		<category><![CDATA[interpreters]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[parsers]]></category>
		<category><![CDATA[perl]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[programming languages]]></category>
		<category><![CDATA[project]]></category>

		<guid isPermaLink="false">http://vivin.net/?p=1317</guid>
		<description><![CDATA[I&#8217;ve added another project to the projects page. It&#8217;s called bAdkOde, an interpreter for an esoteric language that I designed. The very first incarnation of bAdkOde was written in Java and I actually posted it (or made a blog entry about it) over 8 years ago. For some reason I took it down. Probably because [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve added another project to the projects page. It&#8217;s called <strong>bAdkOde</strong>, an interpreter for an <a title="Esoteric language" href="http://en.wikipedia.org/wiki/Esoteric_language" target="_blank">esoteric language</a> that I designed. The very first incarnation of <strong>bAdkOde</strong> was written in Java and I actually <a title="First post about bAdkOde" href="http://vivin.net/2001/04/07/new-interface-and-badkode/" target="_blank">posted it </a>(or made a blog entry about it) over 8 years ago. For some reason I took it down. Probably because I stopped working on it. Anyway, I redesigned the language and wrote an interpreter for it in Perl about 4 or 5 years ago. I finally got around to posting it. <a title="bAdkOde" href="http://vivin.net/projects/badkode/" target="_self">Check out</a> the project page for more details. Let me know what you think.</p>
<br /><a href="http://vivin.net/?p=1317#comments" title="Comments on &quot;bAdkOde: An Esoteric Language&quot;"><img src="http://vivin.net/wp-content/plugins/feed-comments-number/image.php?1317" alt="Comments" /></a><img src="http://vivin.net/?ak_action=api_record_view&#38;id=1317&#38;type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://vivin.net/2009/12/13/badkode-an-esoteric-language/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:thumbnail url="http://vivin.net/wp-content/plugins/feed-comments-number/image.php?1317" />
		<media:content url="http://vivin.net/wp-content/plugins/feed-comments-number/image.php?1317" medium="image">
			<media:title type="html">Comments</media:title>
		</media:content>
		<media:content url="http://vivin.net/?ak_action=api_record_view&#38;id=1317&#38;type=feed" medium="image" />
	</item>
	</channel>
</rss>

