<?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; code</title>
	<atom:link href="http://vivin.net/tag/code/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>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>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>
		<item>
		<title>Sulekha: A text-based Markov-chain generator</title>
		<link>http://vivin.net/2007/07/05/sulekha-a-textbased-markovchain-generator/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=rss</link>
		<comments>http://vivin.net/2007/07/05/sulekha-a-textbased-markovchain-generator/#comments</comments>
		<pubDate>Thu, 05 Jul 2007 22:37:26 +0000</pubDate>
		<dc:creator>vivin</dc:creator>
				<category><![CDATA[Perl]]></category>
		<category><![CDATA[Programming and Development]]></category>
		<category><![CDATA[Projects]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[mark v shaney]]></category>
		<category><![CDATA[markov]]></category>
		<category><![CDATA[markov chain]]></category>
		<category><![CDATA[perl]]></category>
		<category><![CDATA[probability]]></category>
		<category><![CDATA[project]]></category>
		<category><![CDATA[stochastic]]></category>

		<guid isPermaLink="false">http://vivin.net/?p=378</guid>
		<description><![CDATA[I&#8217;ve finished work on the projects page. Sometimes I&#8217;ll have a passing interest in something that leads me to write some code for fun. Yes, you read right. I like to code&#8230; for fun. Anyway, this is something I&#8217;ve done ever since I started programming way back in 1991. I&#8217;ve written a bunch of cool [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve finished work on the <a target = "_blank" href = "http://vivin.net/projects/">projects</a> page. Sometimes I&#8217;ll have a passing interest in something that leads me to write some code for fun. Yes, you read right. I like to code&#8230; for fun. Anyway, this is something I&#8217;ve done ever since I started programming way back in 1991. I&#8217;ve written a bunch of cool little programs over the years. Most of these have been throwaway scripts that I wrote just to &#8220;see what would happen&#8221;. A few of these, however, have had some serious effort put into them. I&#8217;ve decided to showcase these on my site. Hopefully people will find them interesting <img src='http://vivin.net/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> . </p>
<p>The project I&#8217;ve just uploaded is called <em>Sulekha</em>, and is a text-based Markov-chain generator. You can check it out <a target = "_blank" href = "http://vivin.net/projects/sulekha">here</a>. The comments for this journal entry are mirrored on the <em>Sulekha</em> project page, so anything you post here will be visible there (and vice versa). Let me know what you think. Oh, and it&#8217;s interactive so you can generate your own text-based Markov-chains too!</p>
<br /><a href="http://vivin.net/?p=378#comments" title="Comments on &quot;Sulekha: A text-based Markov-chain generator&quot;"><img src="http://vivin.net/wp-content/plugins/feed-comments-number/image.php?378" alt="Comments" /></a><img src="http://vivin.net/?ak_action=api_record_view&#38;id=378&#38;type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://vivin.net/2007/07/05/sulekha-a-textbased-markovchain-generator/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
	
		<media:thumbnail url="http://vivin.net/wp-content/plugins/feed-comments-number/image.php?378" />
		<media:content url="http://vivin.net/wp-content/plugins/feed-comments-number/image.php?378" medium="image">
			<media:title type="html">Comments</media:title>
		</media:content>
		<media:content url="http://vivin.net/?ak_action=api_record_view&#38;id=378&#38;type=feed" medium="image" />
	</item>
		<item>
		<title>Ancient Code</title>
		<link>http://vivin.net/2005/04/15/ancient-code/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=rss</link>
		<comments>http://vivin.net/2005/04/15/ancient-code/#comments</comments>
		<pubDate>Fri, 15 Apr 2005 18:18:55 +0000</pubDate>
		<dc:creator>vivin</dc:creator>
				<category><![CDATA[BASIC]]></category>
		<category><![CDATA[Life]]></category>
		<category><![CDATA[Programming and Development]]></category>
		<category><![CDATA[basic]]></category>
		<category><![CDATA[childhood]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[gw-basic]]></category>
		<category><![CDATA[pack rat]]></category>

		<guid isPermaLink="false">http://vivin.net/?p=315</guid>
		<description><![CDATA[I am a pack rat. I keep anything and everything in the vague hope that I might need it someday. It doesn&#8217;t help when something like that does happen, and I DO need something. Then I feel vindicated and it only serves to re-enforce the behaviour. But anyway, I have these computer disks that are [...]]]></description>
			<content:encoded><![CDATA[<p>I am a pack rat. I keep anything and everything in the vague hope that I might need it someday. It doesn&#8217;t help when something like that does happen, and I DO need something. Then I feel vindicated and it only serves to re-enforce the behaviour. But anyway, I have these computer disks that are more than 11 years old. They are from 1994. They contain a bunch of <a target = "_blank" href = "http://en.wikipedia.org/wiki/GWBASIC">GW-BASIC</a> programs that I wrote. The disks are pretty damn old, and almost falling to pieces. I last used one (the one with all my code) about two years ago and did a directory listing. The only thing that did was screw it up even more. It&#8217;s now impossible to access the disk. But anyway, that&#8217;s on stupid Windows systems. I knew that I could still access data if I really wanted to &#8211; raw data. I put the disk into my FreeBSD machine and ran a <span style = "font-family:courier new">dd</span> command, while ignoring errors. It took a long time, but finally it dumped all my data out to a file. I then ran a <span style = "font-family:courier new">strings</span> command on it to get text. It was like a time-capsule. I saw all this code that I had writted more than a decade ago. I had been programming for at least two or three years then, but 1994 was when I wrote the most code, I think. I went out of my way to make the output messages from my program sound professional. But well, actually it all sounded kinda funny. However, if I hadn&#8217;t done any of that, I wouldn&#8217;t be where I am right now and I wouldn&#8217;t be doing what I do now. This was where it all started&#8230; where I became a programmer. Anyway, here are some snippets, along with my comments:<br />
<span id="more-315"></span><br />
<strong><span style = "text-decoration:underline">Mathvaders</span></strong></p>
<p>I wanted to write a shoot &#8216;em up game (I eventually did later). But I didn&#8217;t know the basics of collision detection, or making objects move around the screen (animation). So I was going to go text based. I was also going to make it something like a Math game or something&#8230; and call it Mathvaders&#8230; see, they invade and they make you do math, so Mathvaders. Yes. I was a smart kid. On the other hand, I have no idea why a sentient alien race would travel lightyears to Planet Earth and make you do Math. But anyway, here goes. First you have the title screen message:</p>
<blockquote><p>
MATHVADERS(TM)<br />
          &#8212;&#8212;&#8212;&#8212;&#8211;<br />
Copyright (C) Vivin Corporations 1995<br />
         All rights reserved
</p></blockquote>
<p>Yes, the awesome Vivin Corporations! Over the coming years, Vivin Corporations would produce even more awesome programs such as the one that emits high pitched siren wails from the computer speakers, or the one that would draw random shapes on the screen! Now I wonder what&#8217;s next&#8230;</p>
<blockquote><p>
Hello! and Welcome to Mathvaders(TM). I hope you enjoy this game. This is a<br />
game made for children to enjoy mathematics. Adults can also play this game to<br />
sharpen their mathematical skills.<br />
   To copy Mathvaders(TM) to your hard disk, just type COPYA if the backup di-<br />
sk is in the A drive or COPYB if the backup disk is in the B drive, at the DOS-<br />
prompt. To start the game, type MV at the DOS prompt. But remember&#8230; <span style = "color:">THIS GA-<br />
ME WILL NOT FUNCTION WITH ANY OF IT&#8217;S FILES MISSIMG!!</span> Keep the main disk in a<br />
safe place so that you can copy the game again if the files are deleted accid-<br />
entally.<br />
    Older computers may take time in displaying certain graphics. But don&#8217;t w-<br />
 orry. That won&#8217;t spoil the fun of the game!!
</p></blockquote>
<p>The English sounds a little bit stilted. That&#8217;s because it&#8217;s <a target = "_blank" href = "http://en.wikipedia.org/wiki/Indian_English">Indian English</a>. Also, the hyphens are at odd places because I was trying to fit the words on the screen. But I didn&#8217;t understand the rules of hyphenation whereby you are only supposed to split words between syllables. </p>
<br /><a href="http://vivin.net/?p=315#comments" title="Comments on &quot;Ancient Code&quot;"><img src="http://vivin.net/wp-content/plugins/feed-comments-number/image.php?315" alt="Comments" /></a><img src="http://vivin.net/?ak_action=api_record_view&#38;id=315&#38;type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://vivin.net/2005/04/15/ancient-code/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:thumbnail url="http://vivin.net/wp-content/plugins/feed-comments-number/image.php?315" />
		<media:content url="http://vivin.net/wp-content/plugins/feed-comments-number/image.php?315" medium="image">
			<media:title type="html">Comments</media:title>
		</media:content>
		<media:content url="http://vivin.net/?ak_action=api_record_view&#38;id=315&#38;type=feed" medium="image" />
	</item>
		<item>
		<title>Artificial Life &#8211; some preliminary findings</title>
		<link>http://vivin.net/2004/10/19/artificial-life-some-preliminary-findings/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=rss</link>
		<comments>http://vivin.net/2004/10/19/artificial-life-some-preliminary-findings/#comments</comments>
		<pubDate>Tue, 19 Oct 2004 22:55:25 +0000</pubDate>
		<dc:creator>vivin</dc:creator>
				<category><![CDATA[Perl]]></category>
		<category><![CDATA[Programming and Development]]></category>
		<category><![CDATA[Projects]]></category>
		<category><![CDATA[Science]]></category>
		<category><![CDATA[artificial life simulator]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[coding for fun]]></category>
		<category><![CDATA[eden]]></category>
		<category><![CDATA[perl]]></category>

		<guid isPermaLink="false">http://vivin.net/?p=312</guid>
		<description><![CDATA[I fnished my artificial life simulator over the weekend, and I have been running simulations on it. There were a few bugs initially that I quickly fixed. My initial simulations gave me some inexplicable &#8220;population explosion&#8221;. For example, in one cycle I would have 31 creatures and in the next cycle I would suddenly have [...]]]></description>
			<content:encoded><![CDATA[<p>I fnished my artificial life simulator over the weekend, and I have been running simulations on it. There were a few bugs initially that I quickly fixed. My initial simulations gave me some inexplicable &#8220;population explosion&#8221;. For example, in one cycle I would have 31 creatures and in the next cycle I would suddenly have around 9,000. It didn&#8217;t make very much sense until I analyzed the log files.</p>
<p>If any of you remember, I mentioned earlier that my &#8220;creatures&#8221; are nothing more than assembly programs. Each of these instructions (and parameters) translate into a bit pattern. Changes in the bit patterns lead to changes in the behaviour of the creature.</p>
<p>One of the instructions is a &#8220;reproduce instruction&#8221;. This prompts the creature to create a copy of itself, with possible mutations. The instruction has a parameter that tells the creature how many copies to create. During the course of the simulation, certain creatures evolved with the reproduce instruction as their first instruction.</p>
<p>My supervisor program (God program) runs one instruction of every creature during one cycle (sort of like an pre-emptive multitasking operating system). If a creature happens to reproduce during the current cycle, then the supervisor program will execute the child&#8217;s instructions as well in that current cycle. This led to an interesting situation. When the mutant that had the reproduce instruction as the first instruction reproduced, its child (if it didn&#8217;t have a mutation that changed the instruction) also had the reproduce instruction as the first instruction. So the supervisor program would run the child, and the child would reproduce with a similar offspring. This went on until a mutant that did not have a &#8220;reproduce instruction&#8221; as the first instruction, evolved. As you can see, this is what led to the population explosion. I corrected this problem by adding &#8220;sexual maturity&#8221; and &#8220;reproductive energy threshold&#8221; parameters to the creatures. Basically, a creature can reproduce only if it has been in existence for a certain number of cycles, and if its current energy is above its reproductive energy threshold. This got rid of the population explosion problem.</p>
<p>My simulations gave me some other interesting results. One of the instructions that I have is a MOV instruction. This instruction moves a creature from one cell in the two-dimensional array to another cell. There is a variant of this instruction, known as the MOVA instruction. In the MOV instruction, if the creature tries to move to an occupied cell, it will retreat to its original position. However, in the MOVA instruction the creature will try to kill (and subsequently eat) the occupant if the destination cell is occupied. I had created a creature that simply ate, reproduced, and moved to different cells. I noted that after many generations, this creature had evolved into an aggressive one, that would eat, reproduce, and move aggressively (MOVA) into other cells. That was rather interesting!</p>
<p>I also saw natural selection at work. When I corrected my population explosion problem, I made it so that the reproductive threshold of a creature was higher than its initial (starting) energy. Over the course of many cycles, I saw that the creatures evolved such that the initial energy would be very high, and that their reproductive threshold would be very low. In additon, their reproductive age was lowered. I thought that my creatures were having it too easy, so I modified my code to make reproduction a costly instruction. After running my simulation, I noticed the opposite! Now the creatures evolved such that the reproductive energy threshold would be much higher than their initial energy. It would seem that the creatures wanted to build up enough energy to where they would be able to reproduce successfuly.</p>
<p>There is also one <em>very interesting</em> behaviour that I noticed. I provide branch instructions in my instruction set. A creature can branch to any part of its code. In addition, I also have a Decrement and Branch instruction that is useful for iterative loops. One of my creatures evolved a clever strategy. It would decrement and branch <em>into the middle</em> of the branch instruction. When I analyzed the code, I noticed in doing so, the creature was performing a MOVA instruction in <em>fewer</em>  bytes than writing an explicit MOVA instruction. It also had the added benefit of performing the MOVA instruction in an iterative fashion so that it could travel around the two-dimensional array. There was a reason for this kind of behaviour though. A creature consumes energy when it performs an instruction, and the energy consumption is proportional to its code size, so it is amazing, but not surprising that such behaviour could arise.</p>
<p>There is still more work that I need to do. I am thinking of giving my creatures some &#8220;memory&#8221; in the form of stack and RAM. They will have some Store, Load, Push and Pop instructions whereby they can write to and read from memory.  Also, I am thinking of adding some more &#8220;registers&#8221;. Right now, the creatures have two count registers for performing iterative loops. My reason for adding more is this &#8211; I want the creatures to be able to act on the data in memory. For example, I can provide instructions that allow the creature to check the status of a particular cell, like if it is occupied, how much food it has, and so on. The creature can load data into the registers, and then use these registers as arguments for the cell checking instructions. This way I am hoping that my creatures will be able to evolve some rudimentary form of &#8220;intelligence&#8221;, or &#8220;intelligent&#8221; behavior.  This will also increase my instruction set. Right now, if a mutation results in an invalid instruction, the creature dies when it tries to execute it. Actually, that reminds me &#8211; I had creatures that evolved with invalid instructions, but they had also evolved branch instructions that would <strong>jump over</strong> the invalid section of code!</p>
<p>Most of these complex behaviours aren&#8217;t that surprising when you consider natural selection&#8230; it is only err&#8230; natural that such behaviour should arise!</p>
<p>Well I guess that&#8217;s all I have for now. I might make a separate page for this project where I can describe this project in more detail. I&#8217;ll post more updates here after I run more simulations.</p>
<br /><a href="http://vivin.net/?p=312#comments" title="Comments on &quot;Artificial Life &#8211; some preliminary findings&quot;"><img src="http://vivin.net/wp-content/plugins/feed-comments-number/image.php?312" alt="Comments" /></a><img src="http://vivin.net/?ak_action=api_record_view&#38;id=312&#38;type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://vivin.net/2004/10/19/artificial-life-some-preliminary-findings/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:thumbnail url="http://vivin.net/wp-content/plugins/feed-comments-number/image.php?312" />
		<media:content url="http://vivin.net/wp-content/plugins/feed-comments-number/image.php?312" medium="image">
			<media:title type="html">Comments</media:title>
		</media:content>
		<media:content url="http://vivin.net/?ak_action=api_record_view&#38;id=312&#38;type=feed" medium="image" />
	</item>
	</channel>
</rss>

