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

<channel>
	<title>dmtg.me.uk</title>
	<atom:link href="http://dmtg.me.uk/feed/?cat=%2Fme&#038;page=About%20Me" rel="self" type="application/rss+xml" />
	<link>http://dmtg.me.uk</link>
	<description>do mind the gap</description>
	<lastBuildDate>Fri, 02 Nov 2012 02:54:24 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.5.1</generator>
		<item>
		<title>Remainder Math Problem</title>
		<link>http://dmtg.me.uk/2012/08/06/remainder-math-problem/</link>
		<comments>http://dmtg.me.uk/2012/08/06/remainder-math-problem/#comments</comments>
		<pubDate>Mon, 06 Aug 2012 20:27:13 +0000</pubDate>
		<dc:creator>patrick</dc:creator>
				<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://dmtg.me.uk/?p=185</guid>
		<description><![CDATA[What is the smallest positive integer that leaves a remainder of 1 when divided by 2, a remainder of 2 when divided by 3, a remainder of 3 when divided by 4, and following the same pattern up to leaving a remainder of 9 when divided by 10? Courtesy of Funnymonkey9696 on Reddit Simple Python [...]]]></description>
				<content:encoded><![CDATA[<blockquote><p>
  What is the smallest positive integer that leaves a remainder of 1 when divided by 2, a remainder of 2 when divided by 3, a remainder of 3 when divided by 4, and following the same pattern up to leaving a remainder of 9 when divided by 10?</p>
</blockquote>
<p>Courtesy of <a href="http://www.reddit.com/r/IAmA/comments/xrb7c/im_a_female_who_has_worked_at_two_erotic/c5oxlyn">Funnymonkey9696</a> on Reddit</p>
<p>Simple Python Solution finder:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="python" style="font-family:monospace;">found <span style="color: #66cc66;">=</span> <span style="color: #008000;">False</span>
num <span style="color: #66cc66;">=</span> -<span style="color: #ff4500;">1</span>
<span style="color: #ff7700;font-weight:bold;">while</span> <span style="color: #ff7700;font-weight:bold;">not</span> found:
    num +<span style="color: #66cc66;">=</span> <span style="color: #ff4500;">1</span>
    found <span style="color: #66cc66;">=</span> <span style="color: #008000;">True</span>
    <span style="color: #ff7700;font-weight:bold;">for</span> i <span style="color: #ff7700;font-weight:bold;">in</span> <span style="color: #008000;">range</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">2</span><span style="color: #66cc66;">,</span> <span style="color: #ff4500;">10</span><span style="color: black;">&#41;</span>:
        <span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: #ff7700;font-weight:bold;">not</span> num % i <span style="color: #66cc66;">==</span> i - <span style="color: #ff4500;">1</span>:
            found <span style="color: #66cc66;">=</span> <span style="color: #008000;">False</span>
<span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">&quot;Blah: &quot;</span> + <span style="color: #008000;">str</span><span style="color: black;">&#40;</span>num<span style="color: black;">&#41;</span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://dmtg.me.uk/2012/08/06/remainder-math-problem/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>A true six word story</title>
		<link>http://dmtg.me.uk/2012/07/23/a-true-six-word-stor/</link>
		<comments>http://dmtg.me.uk/2012/07/23/a-true-six-word-stor/#comments</comments>
		<pubDate>Mon, 23 Jul 2012 14:08:44 +0000</pubDate>
		<dc:creator>patrick</dc:creator>
				<category><![CDATA[Writing]]></category>

		<guid isPermaLink="false">http://dmtg.me.uk/?p=178</guid>
		<description><![CDATA[Went outside: red-hot; staying inside now. I was just relaxing all cool inside my ground floor room, having just taken a shower, when my mom asked me to mow the lawn. Now I am trenched in sweat. This is ridiculous. But as I said, at least my room is extremely cool.]]></description>
				<content:encoded><![CDATA[<blockquote>
<p>Went outside: red-hot; staying inside now.</p>
</blockquote>
<p>I was just relaxing all cool inside my ground floor room, having just taken a shower, when my mom asked me to mow the lawn. Now I am trenched in sweat. This is ridiculous. But as I said, at least my room is extremely cool.</p>
]]></content:encoded>
			<wfw:commentRss>http://dmtg.me.uk/2012/07/23/a-true-six-word-stor/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Create Fantasy RPG Maps using Pixelmator</title>
		<link>http://dmtg.me.uk/2012/07/11/create-fantasy-rpg-maps-using-pixelmator/</link>
		<comments>http://dmtg.me.uk/2012/07/11/create-fantasy-rpg-maps-using-pixelmator/#comments</comments>
		<pubDate>Wed, 11 Jul 2012 08:48:26 +0000</pubDate>
		<dc:creator>patrick</dc:creator>
				<category><![CDATA[Games]]></category>
		<category><![CDATA[RPG]]></category>

		<guid isPermaLink="false">http://dmtg.me.uk/?p=99</guid>
		<description><![CDATA[I&#8217;ve been using Pixelmator for the Mac since forever now. It&#8217;s an amazing piece of software that allows you to do quite a lot of image processing and creation for a very small price. Recently I&#8217;ve been experimenting with doing some RPG Maps and I thought I should put together a little process in case anybody [...]]]></description>
				<content:encoded><![CDATA[<p>I&#8217;ve been using <a href="http://www.pixelmator.com/">Pixelmator</a> for the Mac since forever now. It&#8217;s an amazing piece of software that allows you to do quite a lot of image processing and creation for a very small price. Recently I&#8217;ve been experimenting with doing some <a href="http://rpg.dmtg.me.uk/map">RPG Maps</a> and I thought I should put together a little process in case anybody is interested in how one can do such a thing in Pixelmator quite easily.</p>
<pre><iframe src="http://www.youtube.com/embed/47QlLL7iUws?version=3&amp;wmode=transparent" width="560" height="340" style="background-color:#000;display:block;margin-bottom:0;max-width:100%;" title="YouTube video player" frameborder="0" allowfullscreen></iframe><p style="font-size:11px;margin-top:0;"><a href="http://www.youtube.com/watch?v=47QlLL7iUws" target="_blank" title="Watch on YouTube">Watch this video on YouTube</a>.</p></pre>
<p>My maps don&#8217;t look amazing, but I think for the kind of effort involved they do look quite reasonable (The map in the video is created in &lt; 20 minutes and I think if you invested another 20 it would be a perfectly fine map).</p>
<p>Here&#8217;s one of my first completed ones, where I tried out things:</p>
<p style="text-align: center;"><a href="http://dmtg.me.uk/wp-content/uploads/2012/07/Map.png"><img class="aligncenter  wp-image-100" title="Map" src="http://dmtg.me.uk/wp-content/uploads/2012/07/Map-1024x791.png" alt="" width="491" height="380" /></a></p>
<p>And here is one I am currently using:</p>
<p style="text-align: center;"><a href="http://dmtg.me.uk/wp-content/uploads/2012/07/Map_v2.png"><img class="aligncenter  wp-image-101" title="Map_v2" src="http://dmtg.me.uk/wp-content/uploads/2012/07/Map_v2-1024x791.png" alt="" width="491" height="380" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://dmtg.me.uk/2012/07/11/create-fantasy-rpg-maps-using-pixelmator/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Perfect Ice Tea</title>
		<link>http://dmtg.me.uk/2012/07/08/perfect-ice-tea/</link>
		<comments>http://dmtg.me.uk/2012/07/08/perfect-ice-tea/#comments</comments>
		<pubDate>Sun, 08 Jul 2012 22:01:29 +0000</pubDate>
		<dc:creator>patrick</dc:creator>
				<category><![CDATA[Personal]]></category>

		<guid isPermaLink="false">http://dmtg.me.uk/?p=87</guid>
		<description><![CDATA[For future reference: My Ice Tea recipe is for 2L of Ice Tea 3 bags of Green Tea with Lemon Taste 3 bags of Earl Grey 1 bag of &#8220;Sweet Chili&#8221; tea 1 bag of Fruit tea Let it brew for about 20 minutes, then add sugar while the stuff is still hot. Quite a lot [...]]]></description>
				<content:encoded><![CDATA[<p>For future reference: My Ice Tea recipe is for 2L of Ice Tea</p>
<ul>
<li>3 bags of Green Tea with Lemon Taste</li>
<li>3 bags of Earl Grey</li>
<li>1 bag of &#8220;Sweet Chili&#8221; tea</li>
<li>1 bag of Fruit tea</li>
</ul>
<p>Let it brew for about 20 minutes, then add sugar while the stuff is still hot. Quite a lot of it actually, maybe 170-200g or so. Refrigerate forever until it is finally cold.</p>
]]></content:encoded>
			<wfw:commentRss>http://dmtg.me.uk/2012/07/08/perfect-ice-tea/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Chapters In &#8216;Game Of Thrones&#8217;</title>
		<link>http://dmtg.me.uk/2012/06/23/chapters-in-game-of-thrones/</link>
		<comments>http://dmtg.me.uk/2012/06/23/chapters-in-game-of-thrones/#comments</comments>
		<pubDate>Sat, 23 Jun 2012 21:50:56 +0000</pubDate>
		<dc:creator>patrick</dc:creator>
				<category><![CDATA[Books]]></category>

		<guid isPermaLink="false">http://dmtg.me.uk/?p=79</guid>
		<description><![CDATA[I like statistics and analyzing useless stuff, so excuse this post. In this post I am looking at the book &#8216;Game of Thrones&#8217; by George R. R. Martin. First I divided the ebook into seperate files by using csplit and then I counted the total words of each chapter using wc. In Numbers I then [...]]]></description>
				<content:encoded><![CDATA[<p>I like statistics and analyzing useless stuff, so excuse this post.</p>
<p>In this post I am looking at the book &#8216;Game of Thrones&#8217; by George R. R. Martin. First I divided the ebook into seperate files by using csplit and then I counted the total words of each chapter using wc. In Numbers I then sumed it all up and this is the result:</p>
<p><a href="http://dmtg.me.uk/wp-content/uploads/2012/06/Character-Overview.png"><img class="alignnone size-full wp-image-81" title="Character Overview" src="http://dmtg.me.uk/wp-content/uploads/2012/06/Character-Overview.png" alt="" width="287" height="168" /></a></p>
<p>(Note that Prologue is a character to make it easier to deal with it)</p>
<p>The average length of a chapter in &#8216;Game of Thrones&#8217; is 4,007 words and the total amount of words is 292,492 words.</p>
<p>Sweet. Now let&#8217;s visualize it a bit:</p>
<p><a href="http://dmtg.me.uk/wp-content/uploads/2012/06/Character-Word-Percentage.png"><img class="alignnone size-full wp-image-82" title="Character Word Percentage" src="http://dmtg.me.uk/wp-content/uploads/2012/06/Character-Word-Percentage.png" alt="" width="396" height="385" /></a></p>
<p>In this pie chart we can see what percentage of the total word count each character has in the book.</p>
<p><a href="http://dmtg.me.uk/wp-content/uploads/2012/06/Average-Chapter-Length-By-Character.png"><img class="alignnone size-full wp-image-80" title="Average Chapter Length By Character" src="http://dmtg.me.uk/wp-content/uploads/2012/06/Average-Chapter-Length-By-Character.png" alt="" width="489" height="215" /></a></p>
<p>In this chart we can see the average amount of words a chapter of a character has.</p>
]]></content:encoded>
			<wfw:commentRss>http://dmtg.me.uk/2012/06/23/chapters-in-game-of-thrones/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Old Garbage?</title>
		<link>http://dmtg.me.uk/2012/06/22/old-garbage/</link>
		<comments>http://dmtg.me.uk/2012/06/22/old-garbage/#comments</comments>
		<pubDate>Fri, 22 Jun 2012 10:27:12 +0000</pubDate>
		<dc:creator>patrick</dc:creator>
				<category><![CDATA[Games]]></category>

		<guid isPermaLink="false">http://dmtg.me.uk/?p=73</guid>
		<description><![CDATA[Mom found my old gameboy (+ my sister&#8217;s GBC) and some of our games in the attic. &#8220;I can throw that away, right?&#8221; &#8220;I will kill you if you do. I&#8217;m not even kidding.&#8221; (Also: the save on the Blue was from my sister; she was surprisingly a decent trainer as it seems, three legendaries [...]]]></description>
				<content:encoded><![CDATA[<p><a href="http://dmtg.me.uk/wp-content/uploads/2012/06/IMG_0030.jpg"><img class="alignnone  wp-image-74" title="IMG_0030" src="http://dmtg.me.uk/wp-content/uploads/2012/06/IMG_0030-1024x768.jpg" alt="" width="100%" /></a></p>
<p>Mom found my old gameboy (+ my sister&#8217;s GBC) and some of our games in the attic. &#8220;I can throw that away, right?&#8221;</p>
<p>&#8220;I will kill you if you do. I&#8217;m not even kidding.&#8221;</p>
<p>(Also: the save on the Blue was from my sister; she was surprisingly a decent trainer as it seems, three legendaries in her roaster.)</p>
]]></content:encoded>
			<wfw:commentRss>http://dmtg.me.uk/2012/06/22/old-garbage/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Fix Steam Downloads constantly being suspended</title>
		<link>http://dmtg.me.uk/2012/05/26/fix-steam-downloads-constantly-being-suspended/</link>
		<comments>http://dmtg.me.uk/2012/05/26/fix-steam-downloads-constantly-being-suspended/#comments</comments>
		<pubDate>Sat, 26 May 2012 05:52:08 +0000</pubDate>
		<dc:creator>patrick</dc:creator>
				<category><![CDATA[Games]]></category>

		<guid isPermaLink="false">http://dmtg.me.uk/?p=51</guid>
		<description><![CDATA[This is a repost of a blog post from my previous blog, for which I still get quite a bit of hits from google. Hopefully it is still helpful for people: Almost every Steam User knows it: Suspended Downloads which just won&#8217;t finish. Here are my 2 cents on how to fix them in almost [...]]]></description>
				<content:encoded><![CDATA[<p>This is a repost of a blog post from my previous blog, for which I still get quite a bit of hits from google. Hopefully it is still helpful for people:</p>
<p>Almost every Steam User knows it: Suspended Downloads which just won&#8217;t finish. Here are my 2 cents on how to fix them in almost any situation:</p>
<ul>
<li>Downloads will be suspended when you <strong>launch a game</strong>. If that&#8217;s what you did, then just pause them and unpause them. The download should then continue.</li>
<li>The Steam folder or some subdirectories are set to <strong>&#8220;Read Only&#8221;</strong>. Uncheck that option for the Steam folder. (This should be the number one thing on Windows at least)</li>
<ul>
<li>(The Mac equivalent of sort is to <a href="http://kb.iu.edu/data/aoxn.html">Repair Permissions</a> on your root drive. Just to be save you can check the read-only thing as well using &#8220;Get Info&#8221; on the steam folder in <code>~/Library/Application Support</code> and checking if it says &#8220;Read &amp; Write&#8221; next to your username in the permission section. I&#8217;ve never seen permission change by themselves on the Mac thought, seems to be only with the Windows version of Steam.)</li>
</ul>
<li>If you are using a non-english Operating System you can try to <a href="http://windows.microsoft.com/en-US/windows-vista/Change-the-system-locale">set your Unicode Language Setting to &#8220;English&#8221;</a> (suggestion by a guy named Elvis in the comments of the previous post).</li>
<li>Exit Steam, go to the Steam-Folder and delete the <strong>&#8220;ClientRegistry.blob&#8221;</strong> file. Now restart Steam (you will have to enter your password again even if you checked to save it).</li>
<li><strong>Verify the game cache</strong> (this option is found in the Properties of the game in the Steam Interface).</li>
<li>Delete a bunch of already downloaded files and reverify the cache.</li>
<li>If nothing helps: Delete everything and redownload</li>
</ul>
<p>Those are pretty much the options in the order in which they should be applied.</p>
<p>If everything else fails and you find out how to fix it, please leave me a comment so I can add it to the list.</p>
]]></content:encoded>
			<wfw:commentRss>http://dmtg.me.uk/2012/05/26/fix-steam-downloads-constantly-being-suspended/feed/</wfw:commentRss>
		<slash:comments>16</slash:comments>
		</item>
		<item>
		<title>CYK-Algorithm in newLISP</title>
		<link>http://dmtg.me.uk/2012/05/25/cyk-algorithm-in-newlisp/</link>
		<comments>http://dmtg.me.uk/2012/05/25/cyk-algorithm-in-newlisp/#comments</comments>
		<pubDate>Fri, 25 May 2012 22:39:48 +0000</pubDate>
		<dc:creator>patrick</dc:creator>
				<category><![CDATA[Lisp]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://dmtg.me.uk/?p=20</guid>
		<description><![CDATA[At first we need some basic definitions as to what we are actually calculating here. The CYK-Algorithm requires a context-free grammar. For simplicity we assume that it is given in Chomsky normal form. For this example I&#8217;ve used this grammar: S -> TS &#124; XS &#124; a T -> TT &#124; YY &#124; YS X [...]]]></description>
				<content:encoded><![CDATA[<p>At first we need some basic definitions as to what we are actually calculating here. The <a href="http://en.wikipedia.org/wiki/CYK_algorithm">CYK-Algorithm</a> requires a context-free grammar. For simplicity we assume that it is given in Chomsky normal form. For this example I&#8217;ve used this grammar:</p>
<ul>
<li>S -> TS | XS | a</li>
<li>T -> TT | YY | YS</li>
<li>X -> a</li>
<li>Y -> b</li>
</ul>
<p>The word we are going to look for is &#8220;abbbaa&#8221;. This is an example given to me in a homework assignment in the FGdI 1 class during the summer of 2012 (taught by <a href="http://en.wikipedia.org/wiki/Ulrich_Kohlenbach">Ulrich Kohlenbach</a>).</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="lisp" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">;; Grammar must be in Chomsky normal form.</span>
<span style="color: #808080; font-style: italic;">;; symbols are written in uppercase, terminals in lowercase</span>
<span style="color: #808080; font-style: italic;">;; A -&gt; BC becomes a list with the string &quot;A&quot; as the first element,</span>
<span style="color: #808080; font-style: italic;">;; followed by another list (containing &quot;BC&quot;) as the second element. If a </span>
<span style="color: #808080; font-style: italic;">;; symbol maps to more than one thing, then they can be added to the list</span>
<span style="color: #808080; font-style: italic;">;; along with &quot;BC&quot;.</span>
<span style="color: #808080; font-style: italic;">;; </span>
<span style="color: #808080; font-style: italic;">;; The table here specifies the grammar:</span>
<span style="color: #808080; font-style: italic;">;;    S -&gt; TS | XS | a</span>
<span style="color: #808080; font-style: italic;">;;    T -&gt; TT | YY | YS</span>
<span style="color: #808080; font-style: italic;">;;    X -&gt; a</span>
<span style="color: #808080; font-style: italic;">;;    Y -&gt; b</span>
<span style="color: #66cc66;">&#40;</span>define grammar <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">list</span>
  '<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;S&quot;</span> <span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;TS&quot;</span> <span style="color: #ff0000;">&quot;XS&quot;</span> <span style="color: #ff0000;">&quot;a&quot;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
  '<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;T&quot;</span> <span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;TT&quot;</span> <span style="color: #ff0000;">&quot;YY&quot;</span> <span style="color: #ff0000;">&quot;YS&quot;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
  '<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;X&quot;</span> <span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;a&quot;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
  '<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;Y&quot;</span> <span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;b&quot;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
&nbsp;
<span style="color: #66cc66;">&#40;</span>define startsymbol <span style="color: #ff0000;">&quot;S&quot;</span><span style="color: #66cc66;">&#41;</span>
&nbsp;
<span style="color: #808080; font-style: italic;">;; the word as a string, note that every letter used here should also be a </span>
<span style="color: #808080; font-style: italic;">;; terminal somewhere in the grammar.</span>
<span style="color: #66cc66;">&#40;</span>define word <span style="color: #ff0000;">&quot;abbbaa&quot;</span><span style="color: #66cc66;">&#41;</span></pre></td></tr></table></div>

<p>So much for the easy part. Now we need a function to look up thing in this table for us, as will need to do just that for obvious reasons:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="lisp" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">;; string grammar ~&gt; (listof string)</span>
<span style="color: #808080; font-style: italic;">;; Takes a constructed string which is the construct we are looking for</span>
<span style="color: #808080; font-style: italic;">;; (e.g. &quot;a&quot; for a terminal or &quot;TS&quot; for a symbol construct) and a grammar</span>
<span style="color: #808080; font-style: italic;">;; definition and returns a list of which variables can build this construct</span>
<span style="color: #66cc66;">&#40;</span>define <span style="color: #66cc66;">&#40;</span>find-accepting-productions construct grammar<span style="color: #66cc66;">&#41;</span>
  <span style="color: #66cc66;">&#40;</span>util<span style="color: #66cc66;">:</span><span style="color: #555;">fold</span>
        <span style="color: #66cc66;">&#40;</span>fn <span style="color: #66cc66;">&#40;</span>x v<span style="color: #66cc66;">&#41;</span>
          <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>find construct <span style="color: #66cc66;">&#40;</span>x <span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
              <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">cons</span> <span style="color: #66cc66;">&#40;</span>x <span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#41;</span> v<span style="color: #66cc66;">&#41;</span>
              v<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
        '<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>
        grammar<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span></pre></td></tr></table></div>

<p>Hopefully, this should also be pretty straightforward. The fold function used here is part of my untility collection provided <a href="https://github.com/PatrickLerner/newLISP/blob/master/lib/util.lsp">here on GitHub</a>. It works exactly like the scheme version of fold, so look for documentation for that if you require it. The result of our function here is going to be a list of all the symbols that contain a construct. For example if we use the example grammar I provided and we look at the terminal <code>"a"</code>, the result will be <code>'("S", "X")</code>.</p>
<p>Now let&#8217;s get to the heart of the problem: The CYK algorithm is calculated using a table of sort. I am not going to explain the principle here in detail as there are lots of resources on the internet and in books about it and I am certainly not qualified to teach it, having only just learned it myself. The principle, however is easy and I hope that the comments together with a general understanding should proof sufficient to see what the function is doing.</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="lisp" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">;; number number string grammar ~&gt; (listof string)</span>
<span style="color: #808080; font-style: italic;">;; Calculates which symbols from the grammar are able to produce a cell in</span>
<span style="color: #808080; font-style: italic;">;; the cyk-table.</span>
<span style="color: #66cc66;">&#40;</span>define <span style="color: #66cc66;">&#40;</span>calculate-cell row col word grammar<span style="color: #66cc66;">&#41;</span>
  <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">=</span> row <span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#41;</span>
      <span style="color: #808080; font-style: italic;">;; if we are looking at the first row, this is trivial</span>
      <span style="color: #808080; font-style: italic;">;; just look for a terminal:</span>
      <span style="color: #66cc66;">&#40;</span>find-accepting-productions <span style="color: #66cc66;">&#40;</span>word col<span style="color: #66cc66;">&#41;</span> grammar<span style="color: #66cc66;">&#41;</span>
      <span style="color: #808080; font-style: italic;">;; for subsequent rows it is less trivial, we need recursion</span>
      <span style="color: #808080; font-style: italic;">;;</span>
      <span style="color: #808080; font-style: italic;">;; First, we need to compare 0 to row-1 fields to eachother</span>
      <span style="color: #808080; font-style: italic;">;; the fields in question are calculated as:</span>
      <span style="color: #808080; font-style: italic;">;; k|col and (row - k - 1)|(row + k + 1) where the coordinates are</span>
      <span style="color: #808080; font-style: italic;">;; y|x in the table.</span>
      <span style="color: #808080; font-style: italic;">;;</span>
      <span style="color: #808080; font-style: italic;">;; Now basically, we always need to get the posibilies for these fields</span>
      <span style="color: #808080; font-style: italic;">;; recursively and then try all permuations of the possibilies for these</span>
      <span style="color: #808080; font-style: italic;">;; fields to each other and look if they can be produced by our grammar.</span>
      <span style="color: #66cc66;">&#40;</span>unique <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">apply</span> <span style="color: #b1b100;">append</span> <span style="color: #66cc66;">&#40;</span>map
          <span style="color: #66cc66;">&#40;</span>fn <span style="color: #66cc66;">&#40;</span>k<span style="color: #66cc66;">&#41;</span>
             <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">apply</span> <span style="color: #b1b100;">append</span> <span style="color: #66cc66;">&#40;</span>map
                <span style="color: #66cc66;">&#40;</span>fn <span style="color: #66cc66;">&#40;</span>x<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span>find-accepting-productions x grammar<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
                <span style="color: #66cc66;">&#40;</span>permutations
                  <span style="color: #66cc66;">&#40;</span>calculate-cell k col word grammar<span style="color: #66cc66;">&#41;</span>
                  <span style="color: #66cc66;">&#40;</span>calculate-cell <span style="color: #66cc66;">&#40;</span>- row k <span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span>+ col k <span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span> word grammar<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
          <span style="color: #66cc66;">&#40;</span>sequence <span style="color: #cc66cc;">0</span> <span style="color: #66cc66;">&#40;</span>- row <span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span></pre></td></tr></table></div>

<p>As you can see, I&#8217;ve used a permutations function to combine each of the elements of the first cell with all those of the second cell. This function is pretty straightforward and is provided here:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="lisp" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">;; (listof string) (listof string) ~&gt; (listof string)</span>
<span style="color: #808080; font-style: italic;">;; Creates a list of all possible string permuations from two lists</span>
<span style="color: #808080; font-style: italic;">;; the resulting strings are concatinated together to a single string</span>
<span style="color: #66cc66;">&#40;</span>define <span style="color: #66cc66;">&#40;</span>permutations lst1 lst2<span style="color: #66cc66;">&#41;</span>
  <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">or</span> <span style="color: #66cc66;">&#40;</span>empty? lst1<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span>empty? lst2<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
      <span style="color: #808080; font-style: italic;">;; if either one is empty, then there are no permuations</span>
      '<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>
      <span style="color: #808080; font-style: italic;">;; otherwise:</span>
      <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">apply</span> <span style="color: #b1b100;">append</span>
             <span style="color: #808080; font-style: italic;">;; map over all elements in lst1, then for each of them</span>
             <span style="color: #808080; font-style: italic;">;; map again over those in lst2 and concatinate them</span>
             <span style="color: #66cc66;">&#40;</span>map <span style="color: #66cc66;">&#40;</span>fn <span style="color: #66cc66;">&#40;</span>x<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span>map <span style="color: #66cc66;">&#40;</span>fn <span style="color: #66cc66;">&#40;</span>y<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">append</span> x y<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> lst2<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> lst1<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span></pre></td></tr></table></div>

<p>Last, but not least we can add a couple of more functions to actually print out the result. The easiest one is certainly this one:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="lisp" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">;; string grammar string ~&gt; boolean</span>
<span style="color: #808080; font-style: italic;">;; Returns whether the grammar detects a word based on the startsymbol.</span>
<span style="color: #66cc66;">&#40;</span>define <span style="color: #66cc66;">&#40;</span>grammar-detects-word? word grammar startsymbol<span style="color: #66cc66;">&#41;</span>
  <span style="color: #66cc66;">&#40;</span>find startsymbol <span style="color: #66cc66;">&#40;</span>calculate-cell <span style="color: #66cc66;">&#40;</span>- <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">length</span> word<span style="color: #66cc66;">&#41;</span> <span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span> <span style="color: #cc66cc;">0</span> word grammar<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span></pre></td></tr></table></div>

<p>This function basically returns a boolean whether the word is actually an element of the language created using the provided grammar, but if you actually want to see the table (as I did, since I wanted to check if I did my homework assignment correctly), you can do so as well:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="lisp" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">;; string grammar ~&gt; nul</span>
<span style="color: #808080; font-style: italic;">;; Generates the cyk table and prints it for you</span>
<span style="color: #66cc66;">&#40;</span>define <span style="color: #66cc66;">&#40;</span>gen-and-print-table word grammar<span style="color: #66cc66;">&#41;</span>
  <span style="color: #808080; font-style: italic;">;; header</span>
  <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">print</span> <span style="color: #ff0000;">&quot;V_i/j<span style="color: #000099; font-weight: bold;">\t</span>&quot;</span><span style="color: #66cc66;">&#41;</span>
  <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">dotimes</span> <span style="color: #66cc66;">&#40;</span>x <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">length</span> word<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
      <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">print</span> <span style="color: #66cc66;">&#40;</span>+ <span style="color: #cc66cc;">1</span> x<span style="color: #66cc66;">&#41;</span> <span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\t</span>&quot;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
  <span style="color: #66cc66;">&#40;</span>println<span style="color: #66cc66;">&#41;</span>
  <span style="color: #808080; font-style: italic;">;; print vertical dimension</span>
  <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">dotimes</span> <span style="color: #66cc66;">&#40;</span>y <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">length</span> word<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
      <span style="color: #808080; font-style: italic;">;; print horizontal dimension</span>
      <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">print</span> <span style="color: #66cc66;">&#40;</span>+ y <span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span> <span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\t</span>&quot;</span><span style="color: #66cc66;">&#41;</span>
      <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">dotimes</span> <span style="color: #66cc66;">&#40;</span>x <span style="color: #66cc66;">&#40;</span>- <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">length</span> word<span style="color: #66cc66;">&#41;</span> y<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
          <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">let</span> <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#40;</span>result <span style="color: #66cc66;">&#40;</span>calculate-cell x y word grammar<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
              <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">=</span> result '<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
                  <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">print</span> <span style="color: #ff0000;">&quot;{}&quot;</span><span style="color: #66cc66;">&#41;</span>
                  <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">print</span> <span style="color: #ff0000;">&quot;{&quot;</span>
                         <span style="color: #66cc66;">&#40;</span>util<span style="color: #66cc66;">:</span><span style="color: #555;">join-strings</span> <span style="color: #ff0000;">&quot;, &quot;</span> <span style="color: #66cc66;">&#40;</span>sort result<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
                         <span style="color: #ff0000;">&quot;}&quot;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
                 <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">print</span> <span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\t</span>&quot;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
          <span style="color: #808080; font-style: italic;">;; new line</span>
          <span style="color: #66cc66;">&#40;</span>println<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span></pre></td></tr></table></div>

<p>So that is basically it and if you want, you can also get the complete source code at <a href="https://github.com/PatrickLerner/newLISP/blob/master/attic/cyk.lsp">GitHub</a> instead of copying all the individual parts. In case there are any more questions, feel free to contact me.</p>
]]></content:encoded>
			<wfw:commentRss>http://dmtg.me.uk/2012/05/25/cyk-algorithm-in-newlisp/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>newLISP &#8211; the fun lisp</title>
		<link>http://dmtg.me.uk/2012/05/25/newlisp-the-fun-lisp/</link>
		<comments>http://dmtg.me.uk/2012/05/25/newlisp-the-fun-lisp/#comments</comments>
		<pubDate>Fri, 25 May 2012 21:53:47 +0000</pubDate>
		<dc:creator>patrick</dc:creator>
				<category><![CDATA[Lisp]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[University]]></category>

		<guid isPermaLink="false">http://dmtg.me.uk/?p=11</guid>
		<description><![CDATA[The first time I ever tried anything LISP-like, was about half a year ago in my GdI 1 (&#8216;Grundlagen der Informatik&#8217; or &#8216;Basics of Computer Science&#8217;) class last semester in university. The language of choice for the first 3 months was Racket, a scheme dialect (and java for the remaining three months of the semester) [...]]]></description>
				<content:encoded><![CDATA[<p>The first time I ever tried anything LISP-like, was about half a year ago in my GdI 1 (&#8216;Grundlagen der Informatik&#8217; or &#8216;Basics of Computer Science&#8217;) class last semester in university. The language of choice for the first 3 months was <a href="http://racket-lang.org/">Racket</a>, a scheme dialect (and java for the remaining three months of the semester) and we pretty closely followed the book <a href="http://en.wikipedia.org/wiki/How_to_Design_Programs">How to Design Programs</a>.</p>
<p>Although I have been programming since I was maybe 12 or 13 (maybe even earlier if you count messing around with selfhtml to create text-adventures with links as programming), Racket was different to me. My experience prior to the course were around 4 or 5 years of Delphi, 1.5 years of Java (only used it in my High School CS class and disliked it immediately), some C#, C++ and C knowledge and a bunch of years (5+) in php. A bunch of smaller script in Python and Ruby as well if I think about it, but that&#8217;s pretty much it.</p>
<p>Functional programming itself was not that much of an issue for me &#8211; most of the smaller php scripts I write are functional after all &#8211; and the parentheses quickly stopped bothering me, so I thought it was pretty neat. Although I was not really used to it and now &#8211; in retrospect (if I&#8217;m allowed to say so after just half a year) &#8211; my programs were not very well done. Maybe that&#8217;s because with &#8216;How to Design Programs&#8217; you are limited to subsets of Racket and you are not allowed to use all the functionality as a result (initially not even the debugger!!).</p>
<p>If I had to sum up my experiences, I would say Racket is somewhat mediocre. The language is neat, the functionality &#8211; again in retrospect when comparing it to newLISP &#8211; not as well done, but good enough in general and the included IDE is somewhat buggy in Mac OS X.</p>
<h3>newLISP</h3>
<p><a href="http://dmtg.me.uk/wp-content/uploads/2012/05/newlisp-logo.png"><img class="alignright size-full wp-image-8" title="newlisp-logo" src="http://dmtg.me.uk/wp-content/uploads/2012/05/newlisp-logo.png" alt="" width="240" height="100" /></a>Maybe it&#8217;s just the fact that we are using too much java for my taste, but I recently started to miss messing around with the simple syntax of Racket and I also was looking into trying some new languages to use for general purpose scripting on my system. My usual candidates for that so far have been PHP and Ruby.</p>
<p>PHP is a horrible language from a design standpoint, and prone to produce bad code by people who don&#8217;t know what they are doing, but somehow it can be made to work. Plus using it for scripting does not work even half as well as using it as a web development language in my experience.</p>
<p>Ruby is pretty cool, lots of really neat stuff, but I detest the function commenting style used in RDoc (yard fixes this) and I absolutely hate how 2-spaces indention and &#8211; even worse &#8211; all-lowercase underscore-joining instead of camel case is the de facto default in the Ruby community for naming variables, classes, methods and so on (e.g. <code>some_instance.do_stuff</code> instead of the imho much nicer <code>someInstance.doStuff();</code> even .NET&#8217;s fuggly Pascal-style camel case is better than <em>that</em>).</p>
<p>So I was shopping around: <a href="http://clojure.org/">Clojure</a> looked interesting, but was disqualified for having a ridiculous startup time of 1.5s (<strong>!!!</strong>) and also the JVM/Java integration looks really unappealing to me. Somehow dirty, but I guess that might stem from me disliking java in general.</p>
<p>That&#8217;s when I almost gave up hope and experimented with writing my own Lisp/Scheme like runtime for smallish scripts, first in <a href="https://github.com/PatrickLerner/Awful-Ruby">Ruby</a> and then (against all better senses) in <a href="https://github.com/PatrickLerner/Awful">Java</a> (I wanted something faster than Ruby and it was between Java and C++, so I bit the bullet, although I actually regretted it and I have a unfinished C++ version which only misses lambda compared to the java version on my hard drive as well now).</p>
<p>That&#8217;s when I stumbled upon <a href="http://www.newlisp.org/">newLISP</a> and I saw that it was everything I wanted to have and tried to do myself; amazing!</p>
<p>It has a simple lisp-like syntax, without any old crufty legacy stuff like Common Lisp has it, not too minimalistic, but not too bloated either. It is well documented, throughly tested and runs on all major platforms. Plus it&#8217;s open source (even if it is the GPL, which I personally think is rather <em>meh</em>, but whatever).</p>
]]></content:encoded>
			<wfw:commentRss>http://dmtg.me.uk/2012/05/25/newlisp-the-fun-lisp/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
