<?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:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>The Limber Lambda &#187; Fun</title>
	<atom:link href="http://thelimberlambda.com/category/fun/feed/" rel="self" type="application/rss+xml" />
	<link>http://thelimberlambda.com</link>
	<description>Eric Smith's technical musings</description>
	<lastBuildDate>Tue, 07 Feb 2012 18:09:32 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='thelimberlambda.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://s2.wp.com/i/buttonw-com.png</url>
		<title>The Limber Lambda &#187; Fun</title>
		<link>http://thelimberlambda.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://thelimberlambda.com/osd.xml" title="The Limber Lambda" />
	<atom:link rel='hub' href='http://thelimberlambda.com/?pushpress=hub'/>
		<item>
		<title>Cheating at Word Games</title>
		<link>http://thelimberlambda.com/2012/01/30/cheating-at-word-games/</link>
		<comments>http://thelimberlambda.com/2012/01/30/cheating-at-word-games/#comments</comments>
		<pubDate>Mon, 30 Jan 2012 17:56:08 +0000</pubDate>
		<dc:creator>Eric Smith</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Fun]]></category>
		<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false">https://skepticabin.wordpress.com/?p=316</guid>
		<description><![CDATA[After a gruelling end of 2011, I’ve finally had an opportunity to have some time off.&#160; When you’re head down having to deal with the stress of trying to reach a deadline, other things tend to get neglected.&#160; In my case, “other things” includes staying up-to-date with the technology status quo, whether it be keeping [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=thelimberlambda.com&amp;blog=2436519&amp;post=316&amp;subd=skepticabin&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><font size="2">After a gruelling end of 2011, I’ve finally had an opportunity to have some time off.&#160; When you’re head down having to deal with the stress of trying to reach a deadline, other things tend to get neglected.&#160; In my case, “other things” includes staying up-to-date with the technology status quo, whether it be keeping pace with my RSS feed or learning new things.</font></p>
<p><font size="2">There has been so much fuss about Ruby that I’ve finally capitulated and decided to learn it.&#160; Learning a new language is nothing to be sniffed at though, it’s a bit like eating an elephant—there’s only one way to do it—small bite by small bite.</font></p>
<p><font size="2">Whenever someone decides to dream up a new language my immediate response is: “why?”.&#160; Why spend all that effort coming up with yet another language when so many already exist?&#160; I’ve decided that the answer seems to be: “because you can”.&#160; Ok, trying to be a little less facetious about it … the reason why new languages pop up is because, of course, there is a need.&#160; If there wasn’t, then any new language would surely die as quickly as it was proposed.</font></p>
<p><font size="2"><a href="http://en.wikipedia.org/wiki/Yukihiro_Matsumoto">Yukihiro Matsumoto</a> says that the guiding principle of Ruby is that of “least surprise”, that is, programming in a language (any language) should be a natural and intuitive process.&#160; One shouldn’t have to fight with the language; after all, computers are there to assist <em>us</em> in getting things done.</font></p>
<h2>Word Games</h2>
<p><font size="2">I’ve become addicted to Zynga’s word games, that is, the ones where you play against other users.&#160; The only issue is though, that lately I’ve had a sneaky suspicion that one or two of my opponents are cheating.&#160; When confronted with a cheater, the only option is take it to ‘em.</font></p>
<p><font size="2">Here’s “Hanging with Friends” a delightfully contrived game where your character gets to hang over runny lava with a bunch of helium balloons being his/her only saving grace.&#160; You make up words and your opponent has to guess them and vice versa.&#160; Incorrectly guessing a word means that you lose a balloon … getting that much closer to the hot stuff.</font></p>
<p><font size="2">If you’re itching to play, you can pair up with a random user.&#160; Despite being chosen randomly (I think) all of my opponents are doing a pretty bang-up job of lava-dunking my little guy, so I figured that it was time for a Ruby script to level the playing field.</font></p>
<p><a href="http://skepticabin.files.wordpress.com/2012/01/beeatch-showing-whollopping.png"><img style="background-image:none;padding-left:0;padding-right:0;display:inline;float:right;padding-top:0;border-width:0;margin:0 5px;" title="beeatch-showing-whollopping" border="0" alt="beeatch-showing-whollopping" align="right" src="http://skepticabin.files.wordpress.com/2012/01/beeatch-showing-whollopping_thumb.png?w=307&#038;h=465" width="307" height="465" /></a></p>
<p><font size="2">There are two opportunities for cheating, that is, a) when trying to guess your opponents word and b) when trying to come up with a word that your opponent needs to guess.&#160; I cheat at both points.&#160; Getting some computer-aided assistance for the former is straightforward, and I might talk about that in another post.&#160; Now though, I want to talk about the latter, that is, coming up with a new word.</font></p>
<p><font size="2">You can’t just choose any word; you’re given a random selection of letters from which to build a word.&#160; How about if we had something that could tell us what words can be made out of the given letter selection?</font></p>
<p><font size="2">Something along the lines of:</font></p>
<ol>
<li><font size="2">Find all permutations of letters for a given set, and …</font> </li>
<li><font size="2">Select those permutations that are actual words.</font> </li>
</ol>
<p><font size="2">Straightforward, really.</font></p>
<h3>English Language Words</h3>
<p><font size="2">There are a whole bunch of word lists for download, categorised in various ways.&#160; I’m not particularly fussy and just went for “<a href="http://wordlist.sourceforge.net/">Kevin’s Word List Page</a>”, in particular, the “Spell Checker Oriented Word Lists” (SCOWL).&#160; The lists comprise a bunch of files, categorised by type of English (UK, US, Canada) and in some other ways.&#160; For the purposes of cheating, I don’t really care, because you don’t get penalised if you enter an incorrectly spelled word—you just have to try again.</font></p>
<p><font size="2">Using SCOWL, to get a list of all words (including some proper nouns), is a matter of …</font></p>
<p><font size="2" face="Lucida Console">cat /tmp/scowl-7.1/final/*</font></p>
<p><font size="2">… after unzipping the SCOWL zip.</font></p>
<h3>Permutations</h3>
<p>I’m not going to pretend that I have some fancy way of figuring out words—my methods in this case are very practical … brute-force-style practical.</p>
<p>The method, then, is straightforward.&#160; Given a target number of letters, and given a selection of letters from which you can choose a word, just find all permutations of those letters fitting within the target number of letters and check whether or not each is a real word.</p>
<p>Example:</p>
<p>All permutations of maximum three letters of the following set of letters: [ “a”, “b”, “c”, “d” ], gives us:</p>
<p>[&quot;a&quot;, &quot;b&quot;, &quot;c&quot;]    <br />[&quot;a&quot;, &quot;b&quot;, &quot;d&quot;]     <br />[&quot;a&quot;, &quot;c&quot;, &quot;b&quot;]     <br />[&quot;a&quot;, &quot;c&quot;, &quot;d&quot;]     <br />[&quot;a&quot;, &quot;d&quot;, &quot;b&quot;]     <br />[&quot;a&quot;, &quot;d&quot;, &quot;c&quot;]     <br />[&quot;b&quot;, &quot;a&quot;, &quot;c&quot;]     <br />[&quot;b&quot;, &quot;a&quot;, &quot;d&quot;]     <br />[&quot;b&quot;, &quot;c&quot;, &quot;a&quot;]     <br />[&quot;b&quot;, &quot;c&quot;, &quot;d&quot;]     <br />[&quot;b&quot;, &quot;d&quot;, &quot;a&quot;]     <br />[&quot;b&quot;, &quot;d&quot;, &quot;c&quot;]     <br />[&quot;c&quot;, &quot;a&quot;, &quot;b&quot;]     <br />[&quot;c&quot;, &quot;a&quot;, &quot;d&quot;]     <br />[&quot;c&quot;, &quot;b&quot;, &quot;a&quot;]     <br />[&quot;c&quot;, &quot;b&quot;, &quot;d&quot;]     <br />[&quot;c&quot;, &quot;d&quot;, &quot;a&quot;]     <br />[&quot;c&quot;, &quot;d&quot;, &quot;b&quot;]     <br />[&quot;d&quot;, &quot;a&quot;, &quot;b&quot;]     <br />[&quot;d&quot;, &quot;a&quot;, &quot;c&quot;]     <br />[&quot;d&quot;, &quot;b&quot;, &quot;a&quot;]     <br />[&quot;d&quot;, &quot;b&quot;, &quot;c&quot;]     <br />[&quot;d&quot;, &quot;c&quot;, &quot;a&quot;]     <br />[&quot;d&quot;, &quot;c&quot;, &quot;b&quot;]</p>
<p>Of those, following are real words: <strong>bad</strong>, <strong>cab</strong>, <strong>cad</strong>, <strong>dab.</strong></p>
<h3>Loading English Words, Ruby-Style</h3>
<p>The easiest way of doing this is to load all words from our word lists into memory, into a <strong>Hash</strong>.&#160; This is fairly pedestrian, and looks like this:</p>
<pre>
<pre style="background-color:#ffffff;width:100%;font-family:consolas,&#039;font-size:12px;margin:0;">  1: <span style="color:#0000ff;">def</span> load_words(path_to_word_files)
</pre>
<pre style="background-color:#ffffff;width:100%;font-family:consolas,&#039;font-size:12px;margin:0;">  2:     <span style="color:#00008b;">raise</span> &quot;<span style="color:#8b0000;">Path \&quot;#{path_to_word_files}\&quot; is not a directory</span>&quot; <span style="color:#0000ff;">unless</span> <a style="color:#ff0000;" href="http://www.ruby-doc.org/docs/rdoc/1.9/classes/File.html">File</a>.directory? path_to_word_files
</pre>
<pre style="background-color:#ffffff;width:100%;font-family:consolas,&#039;font-size:12px;margin:0;">  3:     @words = <a style="color:#ff0000;" href="http://www.ruby-doc.org/docs/rdoc/1.9/classes/Hash.html">Hash</a>.new
</pre>
<pre style="background-color:#ffffff;width:100%;font-family:consolas,&#039;font-size:12px;margin:0;">  4:     <a style="color:#ff0000;" href="http://www.ruby-doc.org/docs/rdoc/1.9/classes/Dir.html">Dir</a>.new(path_to_word_files).each <span style="color:#0000ff;">do</span> |f|
</pre>
<pre style="background-color:#ffffff;width:100%;font-family:consolas,&#039;font-size:12px;margin:0;">  5:         path_to_file = <a style="color:#ff0000;" href="http://www.ruby-doc.org/docs/rdoc/1.9/classes/File.html">File</a>.join(path_to_word_files, f)
</pre>
<pre style="background-color:#ffffff;width:100%;font-family:consolas,&#039;font-size:12px;margin:0;">  6:         <span style="color:#0000ff;">if</span> <a style="color:#ff0000;" href="http://www.ruby-doc.org/docs/rdoc/1.9/classes/File.html">File</a>.file?(path_to_file)
</pre>
<pre style="background-color:#ffffff;width:100%;font-family:consolas,&#039;font-size:12px;margin:0;">  7:             <a style="color:#ff0000;" href="http://www.ruby-doc.org/docs/rdoc/1.9/classes/File.html">File</a>.new(path_to_file).each_line <span style="color:#0000ff;">do</span> |l|
</pre>
<pre style="background-color:#ffffff;width:100%;font-family:consolas,&#039;font-size:12px;margin:0;">  8:                 word_without_newlines = l.<span style="color:#00008b;">chomp</span>
</pre>
<pre style="background-color:#ffffff;width:100%;font-family:consolas,&#039;font-size:12px;margin:0;">  9:                 @words[word_without_newlines] = word_without_newlines
</pre>
<pre style="background-color:#ffffff;width:100%;font-family:consolas,&#039;font-size:12px;margin:0;"> 10:             <span style="color:#0000ff;">end</span>
</pre>
<pre style="background-color:#ffffff;width:100%;font-family:consolas,&#039;font-size:12px;margin:0;"> 11:         <span style="color:#0000ff;">end</span>
</pre>
<pre style="background-color:#ffffff;width:100%;font-family:consolas,&#039;font-size:12px;margin:0;"> 12:     <span style="color:#0000ff;">end</span>
</pre>
<pre style="background-color:#ffffff;width:100%;font-family:consolas,&#039;font-size:12px;margin:0;"> 13: <span style="color:#0000ff;">end</span></pre>
</pre>
<pre>&#160;</pre>
<p>As promised by Matz, this stuff is easy to write and easy to read.&#160; Anyone who has written some Perl can see a influence coming in to Ruby, in particular <strong>chomp</strong> (for removing newlines) and <strong>unless</strong> (used as a statement modifier).</p>
<h3></h3>
<h3>Permutations</h3>
<p>Once all the words have been hashified, what remains is brute-forcing all permutations.&#160; Fortunately, Ruby has permutation-finding <em>built in</em> to its <strong>Array</strong> implementation.&#160; What we need to do becomes:</p>
<pre>
<pre style="background-color:#ffffff;width:100%;font-family:consolas,&#039;font-size:12px;margin:0;">  1: <span style="color:#0000ff;">def</span> get_words_with_letters(letters, word_length=8)
</pre>
<pre style="background-color:#ffffff;width:100%;font-family:consolas,&#039;font-size:12px;margin:0;">  2:     word_length = letters.length <span style="color:#0000ff;">if</span> letters.length &lt; word_length
</pre>
<pre style="background-color:#ffffff;width:100%;font-family:consolas,&#039;font-size:12px;margin:0;">  3:     found = <a style="color:#ff0000;" href="http://www.ruby-doc.org/docs/rdoc/1.9/classes/Hash.html">Hash</a>.new
</pre>
<pre style="background-color:#80ff80;width:100%;font-family:consolas,&#039;font-size:12px;margin:0;">  4:     letters.chars.to_a.permutation(word_length).each <span style="color:#0000ff;">do</span> |permutation|
</pre>
<pre style="background-color:#ffffff;width:100%;font-family:consolas,&#039;font-size:12px;margin:0;">  5:         candidate = permutation.join
</pre>
<pre style="background-color:#ffffff;width:100%;font-family:consolas,&#039;font-size:12px;margin:0;">  6:         <span style="color:#0000ff;">next</span> <span style="color:#0000ff;">if</span> found.has_key?(candidate)
</pre>
<pre style="background-color:#ffffff;width:100%;font-family:consolas,&#039;font-size:12px;margin:0;">  7:         found[candidate] = candidate <span style="color:#0000ff;">if</span> @words.has_key?(candidate)
</pre>
<pre style="background-color:#ffffff;width:100%;font-family:consolas,&#039;font-size:12px;margin:0;">  8:     <span style="color:#0000ff;">end</span>
</pre>
<pre style="background-color:#ffffff;width:100%;font-family:consolas,&#039;font-size:12px;margin:0;">  9:     <span style="color:#0000ff;">return</span> found.keys
</pre>
<pre style="background-color:#ffffff;width:100%;font-family:consolas,&#039;font-size:12px;margin:0;"> 10: <span style="color:#0000ff;">end</span></pre>
</pre>
<pre>&#160;</pre>
<p>In a single chained call on a string containing the letters that we can work with, we:</p>
<ol>
<li>Get an enumeration of characters comprising the string; </li>
<li>Convert the enumeration to an array … </li>
<li>create an array containing all the permutations for a given length of word (each permutation being an array of characters) and </li>
<li>Enumerate the array, passing each item to a block. </li>
</ol>
<p>A few more statements with modifiers gives us a terse but expressive bit of code that eliminates duplicates (as a result of multiple of the same letter being part of the original set), and adds the item if it is a real word.</p>
<p>An initial, rough-and-ready but effective script is now ready to join my arsenal of cobbled-together tools needed to bring humility to any would-be “Hanging” challengers:</p>
<pre>
<pre style="background-color:#ffffff;width:100%;font-family:consolas,&#039;font-size:12px;margin:0;">  1: <span style="color:#008000;">#!/usr/bin/env ruby</span>
</pre>
<pre style="background-color:#ffffff;width:100%;font-family:consolas,&#039;font-size:12px;margin:0;">  2:
</pre>
<pre style="background-color:#ffffff;width:100%;font-family:consolas,&#039;font-size:12px;margin:0;">  3: <span style="color:#0000ff;">class</span> EnglishWords
</pre>
<pre style="background-color:#ffffff;width:100%;font-family:consolas,&#039;font-size:12px;margin:0;">  4:     <span style="color:#0000ff;">def</span> initialize(path_to_word_files)
</pre>
<pre style="background-color:#ffffff;width:100%;font-family:consolas,&#039;font-size:12px;margin:0;">  5:         load_words(path_to_word_files)
</pre>
<pre style="background-color:#ffffff;width:100%;font-family:consolas,&#039;font-size:12px;margin:0;">  6:     <span style="color:#0000ff;">end</span>
</pre>
<pre style="background-color:#ffffff;width:100%;font-family:consolas,&#039;font-size:12px;margin:0;">  7:
</pre>
<pre style="background-color:#ffffff;width:100%;font-family:consolas,&#039;font-size:12px;margin:0;">  8:     <span style="color:#0000ff;">def</span> load_words(path_to_word_files)
</pre>
<pre style="background-color:#ffffff;width:100%;font-family:consolas,&#039;font-size:12px;margin:0;">  9:         <span style="color:#00008b;">raise</span> &quot;<span style="color:#8b0000;">Path \&quot;#{path_to_word_files}\&quot; is not a directory</span>&quot; <span style="color:#0000ff;">unless</span> <a style="color:#ff0000;" href="http://www.ruby-doc.org/docs/rdoc/1.9/classes/File.html">File</a>.directory? path_to_word_files
</pre>
<pre style="background-color:#ffffff;width:100%;font-family:consolas,&#039;font-size:12px;margin:0;"> 10:         @words = <a style="color:#ff0000;" href="http://www.ruby-doc.org/docs/rdoc/1.9/classes/Hash.html">Hash</a>.new
</pre>
<pre style="background-color:#ffffff;width:100%;font-family:consolas,&#039;font-size:12px;margin:0;"> 11:         <a style="color:#ff0000;" href="http://www.ruby-doc.org/docs/rdoc/1.9/classes/Dir.html">Dir</a>.new(path_to_word_files).each <span style="color:#0000ff;">do</span> |f|
</pre>
<pre style="background-color:#ffffff;width:100%;font-family:consolas,&#039;font-size:12px;margin:0;"> 12:             path_to_file = <a style="color:#ff0000;" href="http://www.ruby-doc.org/docs/rdoc/1.9/classes/File.html">File</a>.join(path_to_word_files, f)
</pre>
<pre style="background-color:#ffffff;width:100%;font-family:consolas,&#039;font-size:12px;margin:0;"> 13:             <span style="color:#0000ff;">if</span> <a style="color:#ff0000;" href="http://www.ruby-doc.org/docs/rdoc/1.9/classes/File.html">File</a>.file?(path_to_file)
</pre>
<pre style="background-color:#ffffff;width:100%;font-family:consolas,&#039;font-size:12px;margin:0;"> 14:                 <a style="color:#ff0000;" href="http://www.ruby-doc.org/docs/rdoc/1.9/classes/File.html">File</a>.new(path_to_file).each_line <span style="color:#0000ff;">do</span> |l|
</pre>
<pre style="background-color:#ffffff;width:100%;font-family:consolas,&#039;font-size:12px;margin:0;"> 15:                     word_without_newlines = l.<span style="color:#00008b;">chomp</span>
</pre>
<pre style="background-color:#ffffff;width:100%;font-family:consolas,&#039;font-size:12px;margin:0;"> 16:                     @words[word_without_newlines] = word_without_newlines
</pre>
<pre style="background-color:#ffffff;width:100%;font-family:consolas,&#039;font-size:12px;margin:0;"> 17:                 <span style="color:#0000ff;">end</span>
</pre>
<pre style="background-color:#ffffff;width:100%;font-family:consolas,&#039;font-size:12px;margin:0;"> 18:             <span style="color:#0000ff;">end</span>
</pre>
<pre style="background-color:#ffffff;width:100%;font-family:consolas,&#039;font-size:12px;margin:0;"> 19:         <span style="color:#0000ff;">end</span>
</pre>
<pre style="background-color:#ffffff;width:100%;font-family:consolas,&#039;font-size:12px;margin:0;"> 20:     <span style="color:#0000ff;">end</span>
</pre>
<pre style="background-color:#ffffff;width:100%;font-family:consolas,&#039;font-size:12px;margin:0;"> 21:
</pre>
<pre style="background-color:#ffffff;width:100%;font-family:consolas,&#039;font-size:12px;margin:0;"> 22:     <span style="color:#0000ff;">def</span> get_words_with_letters(letters, word_length=8)
</pre>
<pre style="background-color:#ffffff;width:100%;font-family:consolas,&#039;font-size:12px;margin:0;"> 23:         word_length = letters.length <span style="color:#0000ff;">if</span> letters.length &lt; word_length
</pre>
<pre style="background-color:#ffffff;width:100%;font-family:consolas,&#039;font-size:12px;margin:0;"> 24:         found = <a style="color:#ff0000;" href="http://www.ruby-doc.org/docs/rdoc/1.9/classes/Hash.html">Hash</a>.new
</pre>
<pre style="background-color:#ffffff;width:100%;font-family:consolas,&#039;font-size:12px;margin:0;"> 25:         letters.chars.to_a.permutation(word_length).each <span style="color:#0000ff;">do</span> |permutation|
</pre>
<pre style="background-color:#ffffff;width:100%;font-family:consolas,&#039;font-size:12px;margin:0;"> 26:             candidate = permutation.join
</pre>
<pre style="background-color:#ffffff;width:100%;font-family:consolas,&#039;font-size:12px;margin:0;"> 27:             <span style="color:#0000ff;">next</span> <span style="color:#0000ff;">if</span> found.has_key?(candidate)
</pre>
<pre style="background-color:#ffffff;width:100%;font-family:consolas,&#039;font-size:12px;margin:0;"> 28:             found[candidate] = candidate <span style="color:#0000ff;">if</span> @words.has_key?(candidate)
</pre>
<pre style="background-color:#ffffff;width:100%;font-family:consolas,&#039;font-size:12px;margin:0;"> 29:         <span style="color:#0000ff;">end</span>
</pre>
<pre style="background-color:#ffffff;width:100%;font-family:consolas,&#039;font-size:12px;margin:0;"> 30:         <span style="color:#0000ff;">return</span> found.keys
</pre>
<pre style="background-color:#ffffff;width:100%;font-family:consolas,&#039;font-size:12px;margin:0;"> 31:     <span style="color:#0000ff;">end</span>
</pre>
<pre style="background-color:#ffffff;width:100%;font-family:consolas,&#039;font-size:12px;margin:0;"> 32: <span style="color:#0000ff;">end</span>
</pre>
<pre style="background-color:#ffffff;width:100%;font-family:consolas,&#039;font-size:12px;margin:0;"> 33:
</pre>
<pre style="background-color:#ffffff;width:100%;font-family:consolas,&#039;font-size:12px;margin:0;"> 34: <span style="color:#0000ff;">def</span> print_usage_and_exit
</pre>
<pre style="background-color:#ffffff;width:100%;font-family:consolas,&#039;font-size:12px;margin:0;"> 35:     <span style="color:#00008b;">puts</span> &lt;&lt;EOF
</pre>
<pre style="background-color:#ffffff;width:100%;font-family:consolas,&#039;font-size:12px;margin:0;"> 36: <span style="color:#008000;">#{$0[/[\w\d_-]+/]} &lt;path_to_words&gt; &lt;letters&gt; &lt;word_length&gt;</span>
</pre>
<pre style="background-color:#ffffff;width:100%;font-family:consolas,&#039;font-size:12px;margin:0;"> 37:
</pre>
<pre style="background-color:#ffffff;width:100%;font-family:consolas,&#039;font-size:12px;margin:0;"> 38:     &lt;path_to_words&gt;     A folder containing English word files.  The <span style="color:#00008b;">format</span> of word files
</pre>
<pre style="background-color:#ffffff;width:100%;font-family:consolas,&#039;font-size:12px;margin:0;"> 39:                         is one word per line.
</pre>
<pre style="background-color:#ffffff;width:100%;font-family:consolas,&#039;font-size:12px;margin:0;"> 40:     &lt;letters&gt;           A string of letters, a subset of which determine words to find.
</pre>
<pre style="background-color:#ffffff;width:100%;font-family:consolas,&#039;font-size:12px;margin:0;"> 41:     &lt;length&gt;            Length of words to find (must be less <span style="color:#0000ff;">then</span> the lesser of
</pre>
<pre style="background-color:#ffffff;width:100%;font-family:consolas,&#039;font-size:12px;margin:0;"> 42:                         the length of &lt;letters&gt; <span style="color:#0000ff;">and</span> 9).
</pre>
<pre style="background-color:#ffffff;width:100%;font-family:consolas,&#039;font-size:12px;margin:0;"> 43:
</pre>
<pre style="background-color:#ffffff;width:100%;font-family:consolas,&#039;font-size:12px;margin:0;"> 44:     Example:
</pre>
<pre style="background-color:#ffffff;width:100%;font-family:consolas,&#039;font-size:12px;margin:0;"> 45:
</pre>
<pre style="background-color:#ffffff;width:100%;font-family:consolas,&#039;font-size:12px;margin:0;"> 46:     <span style="color:#008000;">#{$0[/[\w\d_-]+/]} /tmp/scowl/final trasse 5</span>
</pre>
<pre style="background-color:#ffffff;width:100%;font-family:consolas,&#039;font-size:12px;margin:0;"> 47:
</pre>
<pre style="background-color:#ffffff;width:100%;font-family:consolas,&#039;font-size:12px;margin:0;"> 48:     yields:
</pre>
<pre style="background-color:#ffffff;width:100%;font-family:consolas,&#039;font-size:12px;margin:0;"> 49:
</pre>
<pre style="background-color:#ffffff;width:100%;font-family:consolas,&#039;font-size:12px;margin:0;"> 50:     tasser
</pre>
<pre style="background-color:#ffffff;width:100%;font-family:consolas,&#039;font-size:12px;margin:0;"> 51:     tasers
</pre>
<pre style="background-color:#ffffff;width:100%;font-family:consolas,&#039;font-size:12px;margin:0;"> 52:     terass
</pre>
<pre style="background-color:#ffffff;width:100%;font-family:consolas,&#039;font-size:12px;margin:0;"> 53:     reasts
</pre>
<pre style="background-color:#ffffff;width:100%;font-family:consolas,&#039;font-size:12px;margin:0;"> 54:     asters
</pre>
<pre style="background-color:#ffffff;width:100%;font-family:consolas,&#039;font-size:12px;margin:0;"> 55:     assert
</pre>
<pre style="background-color:#ffffff;width:100%;font-family:consolas,&#039;font-size:12px;margin:0;"> 56:     straes
</pre>
<pre style="background-color:#ffffff;width:100%;font-family:consolas,&#039;font-size:12px;margin:0;"> 57:     stares
</pre>
<pre style="background-color:#ffffff;width:100%;font-family:consolas,&#039;font-size:12px;margin:0;"> 58:     stears
</pre>
<pre style="background-color:#ffffff;width:100%;font-family:consolas,&#039;font-size:12px;margin:0;"> 59:     essart
</pre>
<pre style="background-color:#ffffff;width:100%;font-family:consolas,&#039;font-size:12px;margin:0;"> 60: EOF
</pre>
<pre style="background-color:#ffffff;width:100%;font-family:consolas,&#039;font-size:12px;margin:0;"> 61:     <span style="color:#00008b;">exit</span> -1
</pre>
<pre style="background-color:#ffffff;width:100%;font-family:consolas,&#039;font-size:12px;margin:0;"> 62: <span style="color:#0000ff;">end</span>
</pre>
<pre style="background-color:#ffffff;width:100%;font-family:consolas,&#039;font-size:12px;margin:0;"> 63:
</pre>
<pre style="background-color:#ffffff;width:100%;font-family:consolas,&#039;font-size:12px;margin:0;"> 64: print_usage_and_exit <span style="color:#0000ff;">if</span> ARGV.length &lt; 3
</pre>
<pre style="background-color:#ffffff;width:100%;font-family:consolas,&#039;font-size:12px;margin:0;"> 65:
</pre>
<pre style="background-color:#ffffff;width:100%;font-family:consolas,&#039;font-size:12px;margin:0;"> 66: words = EnglishWords.new ARGV.shift
</pre>
<pre style="background-color:#ffffff;width:100%;font-family:consolas,&#039;font-size:12px;margin:0;"> 67: letters = ARGV.shift
</pre>
<pre style="background-color:#ffffff;width:100%;font-family:consolas,&#039;font-size:12px;margin:0;"> 68: word_length = ARGV.shift.to_i
</pre>
<pre style="background-color:#ffffff;width:100%;font-family:consolas,&#039;font-size:12px;margin:0;"> 69:
</pre>
<pre style="background-color:#ffffff;width:100%;font-family:consolas,&#039;font-size:12px;margin:0;">

 70: words.get_words_with_letters(letters, word_length).each { |w| <span style="color:#00008b;">puts</span> w }

&#160;
</pre>
</pre>
<p><a href="http://skepticabin.files.wordpress.com/2012/01/image.png"><img style="background-image:none;padding-left:0;padding-right:0;display:inline;padding-top:0;border-width:0;margin:0 5px;" title="image" border="0" alt="image" src="http://skepticabin.files.wordpress.com/2012/01/image_thumb.png?w=675&#038;h=64" width="675" height="64" /></a></p>
<p>I don’t know what a <strong>tostados</strong> is, but “Hanging with Friends” seems happy with it <img style="border-style:none;" class="wlEmoticon wlEmoticon-smile" alt="Smile" src="http://skepticabin.files.wordpress.com/2012/01/wlemoticon-smile.png?w=700" />.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/skepticabin.wordpress.com/316/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/skepticabin.wordpress.com/316/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/skepticabin.wordpress.com/316/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/skepticabin.wordpress.com/316/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/skepticabin.wordpress.com/316/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/skepticabin.wordpress.com/316/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/skepticabin.wordpress.com/316/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/skepticabin.wordpress.com/316/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/skepticabin.wordpress.com/316/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/skepticabin.wordpress.com/316/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/skepticabin.wordpress.com/316/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/skepticabin.wordpress.com/316/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/skepticabin.wordpress.com/316/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/skepticabin.wordpress.com/316/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=thelimberlambda.com&amp;blog=2436519&amp;post=316&amp;subd=skepticabin&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://thelimberlambda.com/2012/01/30/cheating-at-word-games/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/b4cf8c0d26636bfbef4bcba057b27f01?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Serfsmith</media:title>
		</media:content>

		<media:content url="http://skepticabin.files.wordpress.com/2012/01/beeatch-showing-whollopping_thumb.png" medium="image">
			<media:title type="html">beeatch-showing-whollopping</media:title>
		</media:content>

		<media:content url="http://skepticabin.files.wordpress.com/2012/01/image_thumb.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>

		<media:content url="http://skepticabin.files.wordpress.com/2012/01/wlemoticon-smile.png" medium="image">
			<media:title type="html">Smile</media:title>
		</media:content>
	</item>
		<item>
		<title>&#8220;Sharpen Up&#8221; Series: Episode 7</title>
		<link>http://thelimberlambda.com/2009/05/13/sharpen-up-series-episode-7/</link>
		<comments>http://thelimberlambda.com/2009/05/13/sharpen-up-series-episode-7/#comments</comments>
		<pubDate>Wed, 13 May 2009 17:58:06 +0000</pubDate>
		<dc:creator>Eric Smith</dc:creator>
				<category><![CDATA[Fun]]></category>

		<guid isPermaLink="false">http://skepticabin.wordpress.com/?p=161</guid>
		<description><![CDATA[Do you know what a pandigital number is?  Following is the definition from Wikipedia: “In mathematics, a pandigital number is an integer that in a given base has among its significant digits each digit used in the base at least once, for example: 1223334444555567890.” Project Euler problem number 32 modifies the definition a little for [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=thelimberlambda.com&amp;blog=2436519&amp;post=161&amp;subd=skepticabin&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Do you know what a pandigital number is?  Following is the definition from Wikipedia:</p>
<div style="border:1px dotted black;float:left;background-color:#f8f8f8;margin-bottom:1em;margin-left:3em;margin-right:3em;clear:right;padding:.5em;">“In mathematics, a <strong><a href="http://en.wikipedia.org/wiki/Pandigital">pandigital number</a></strong> is an integer that in a given base has among its significant digits each digit used in the base at least once, for example: 1223334444555567890.”</div>
<p style="clear:left;">Project Euler problem <a href="http://projecteuler.net/index.php?section=problems&amp;id=32">number 32</a> modifies the definition a little for the sake of convenience:</p>
<div style="border:1px dotted black;float:left;background-color:#f8f8f8;margin-bottom:1em;margin-left:3em;margin-right:3em;clear:right;padding:.5em;">“We shall say that an <var>n</var>-digit number is pandigital if it makes use of all the digits 1 to <var>n</var> exactly once”</div>
<div style="clear:left;">Note the deviation from the official definition:</div>
<ol style="margin-top:.5em;">
<li>1 to 9 instead of 0 to 9</li>
<li>Each digit occurs <em>only</em> once, instead of <em>at least</em> once.</li>
</ol>
<p>Now if the definition is extended to a multiplicand/multiplier/product <em>identity</em>, that is, like this:</p>
<p style="font-size:large;" align="center">39 × 186 = 7254</p>
<p style="clear:left;">Then the problem becomes:</p>
<div style="float:left;">
<div style="border:1px dotted black;float:left;background-color:#f8f8f8;margin-bottom:1em;margin-left:3em;margin-right:3em;clear:right;padding:.5em;">“Find the sum of all products whose multiplicand/multiplier/product identity can be written as a 1 through 9 pandigital.”</div>
</div>
<p style="clear:left;">A &#8220;hint&#8221; is provided, although I think that this is less of a hint and more of &#8220;additional instructions&#8221;.  As it turns out, the set of answers has multiple identities that result in the same product (and these are not the obvious transpositions of multiplicand and multiplier as one might think), so where there are duplicates, only one instance of the product should be added to the total.  As an example:</p>
<p style="font-size:large;" align="center">18 x 297 = 5346</p>
<p style="font-size:large;" align="center">27 x 198 = 5346</p>
<p>In this case, the second identity is ignored.</p>
<p>This isn&#8217;t a hugely challenging problem &#8211; I would say the only interesting bit is finding the possible 9 digit permutations.  We know that the number of permutations is 9! = 9 x 8 x 7 x 6 x 5 x 4 x 2 = <strong>36288o</strong>.  Given the sort of computing power we have these days, churning through that list should be an absolute doddle.</p>
<h3>Finding Permutations</h3>
<p>I generally try not to defer to &#8220;official algorithms&#8221; when trying to solve problems like these, and as a result end up implementing something that may work but probably is not the most efficient.  There are <a href="http://en.wikipedia.org/wiki/Permutation#Algorithms_to_generate_permutations">various algorithms for calculating permutations</a>, but the one that I came up with is of the recursive variety (recursion is fun).  It goes something like this:</p>
<ol>
<li>mySwapper = { Given a set of n digits (numbered 1 &#8230; n), swap digit i with the remaining digits where i goes from 1 &#8230; n.  For each iteration of i, return mySwapper(&lt;remaining digits&gt;) }</li>
<li>mySwapper(&lt;all the digits&gt;)</li>
</ol>
<p>Note that we obviously don&#8217;t need to swap digit <em>k</em> with digit <em>k</em>, but to keep the algorithm neat (read: exception-free) we&#8217;ll sacrifice a little performance.</p>
<h3>Producing the Sum</h3>
<p>Once we have all the possible permutations of 9 digits, what remains is to split them up into multiplicand/multiplier/product parts and test that the product is correct.  Now, since we only have 9 digits, we can make use of some common sense rules re products, that is, a product will always have at least as many digits as the sum of multiplicand and multiplier digits minus 1.  The only multiplicand/multiplier/product combinations that satisfy this condition are <strong>2/3/4</strong> and <strong>1/4/4</strong> (well &#8230; 3/2/4 and 4/1/4 as well, but these provide duplicate answers).</p>
<p>What remains is to check that we don&#8217;t add duplicate products (like the one shown above), and to calculate the sum.  I&#8217;ve included the source code in C# below&#8211;I&#8217;m not claiming that this is particularly efficient at all though, I&#8217;m quite sure there are much faster ways of doing this using <code>System.Int32</code>&#8216;s only:</p>
<p><pre class="brush: csharp;">
using System;
using System.Collections.Generic;

class ProjectEuler32
{
    static void Main(string[] args)
    {
        var permutations = GetDigitPermutations();
        var alreadyHave = new HashSet&lt;string&gt;();
        Console.WriteLine(
            &quot;Total: &quot; +
            (GetMultiplicationComboSum(1, 4, permutations, alreadyHave) +
            GetMultiplicationComboSum(2, 3, permutations, alreadyHave)));
        Console.ReadLine();
    }

    static int GetMultiplicationComboSum(int multiplicandLen, int multiplierLen, char[][] permutationSet,
        HashSet&lt;string&gt; alreadyHave)
    {
        int sum = 0;
        for (int i = 0; i &lt; permutationSet.Length; i++)
        {
			var productString = new String(permutationSet[i], multiplicandLen + multiplierLen,
				9 - multiplicandLen - multiplierLen);
			var multiplicandString = new String(permutationSet[i], 1, multiplicandLen);
			var multiplierString = new String(permutationSet[i], multiplicandLen, multiplierLen);
			var product = Convert.ToInt32(productString);
            if (Convert.ToInt32(multiplicandString) * Convert.ToInt32(multiplierString) == product)
            {
                if (alreadyHave.Contains(productString))
                {
                    Console.Write(&quot;Already have: &quot;);
                }
                else
                {
                    alreadyHave.Add(productString);
                    sum += product;
                }
                Console.WriteLine(multiplicandString + &quot; x &quot; + multiplierString + &quot; = &quot; + productString);
            }
        }
        return sum;
    }

    static char[][] GetDigitPermutations()
    {
        var toFill = new char[9 * 8 * 7 * 6 * 5 * 4 * 3 * 2][];
        var toFillIndex = 0;
        Action&lt;char[], int&gt; permutationFinder = null;
        permutationFinder =
            (ca, ix) =&gt;
            {
                if (ix == 9)
                    toFill[toFillIndex++] = ca;
                else
                {
                    var myca = new char[9];
                    ca.CopyTo(myca, 0);
                    for (var i = ix; i &lt; 9; i++)
                    {
                        var c1 = myca[ix]; myca[ix] = myca[i]; myca[i] = c1;
                        permutationFinder(myca, ix + 1);
                        c1 = myca[ix]; myca[ix] = myca[i]; myca[i] = c1;
                    }
                }
            };
        permutationFinder(new char[] { '1', '2', '3', '4', '5', '6', '7', '8', '9' }, 0);
        return toFill;
    }
}
</pre></p>
<p>And here&#8217;s the output:<img class="aligncenter size-full wp-image-170" title="permutations" src="http://skepticabin.files.wordpress.com/2009/05/permutations.jpg?w=700" alt="permutations"   /></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/skepticabin.wordpress.com/161/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/skepticabin.wordpress.com/161/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/skepticabin.wordpress.com/161/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/skepticabin.wordpress.com/161/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/skepticabin.wordpress.com/161/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/skepticabin.wordpress.com/161/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/skepticabin.wordpress.com/161/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/skepticabin.wordpress.com/161/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/skepticabin.wordpress.com/161/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/skepticabin.wordpress.com/161/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/skepticabin.wordpress.com/161/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/skepticabin.wordpress.com/161/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/skepticabin.wordpress.com/161/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/skepticabin.wordpress.com/161/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=thelimberlambda.com&amp;blog=2436519&amp;post=161&amp;subd=skepticabin&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://thelimberlambda.com/2009/05/13/sharpen-up-series-episode-7/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/b4cf8c0d26636bfbef4bcba057b27f01?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Serfsmith</media:title>
		</media:content>

		<media:content url="http://skepticabin.files.wordpress.com/2009/05/permutations.jpg" medium="image">
			<media:title type="html">permutations</media:title>
		</media:content>
	</item>
		<item>
		<title>&#8220;Sharpen Up&#8221; Series: Episode 6</title>
		<link>http://thelimberlambda.com/2009/05/12/sharpen-up-series-episode-6/</link>
		<comments>http://thelimberlambda.com/2009/05/12/sharpen-up-series-episode-6/#comments</comments>
		<pubDate>Tue, 12 May 2009 14:58:20 +0000</pubDate>
		<dc:creator>Eric Smith</dc:creator>
				<category><![CDATA[Fun]]></category>

		<guid isPermaLink="false">http://skepticabin.wordpress.com/?p=142</guid>
		<description><![CDATA[A colleague brought my attention to this brain-teaser, from Project Euler: The series, 11 + 22 + 33 + 44 + … + 1010 = 10405071317. Find the last ten digits of the series, 11 + 22 + 33 + 44 + … + 10001000 Having a Unix background, my first instinct was to fire [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=thelimberlambda.com&amp;blog=2436519&amp;post=142&amp;subd=skepticabin&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>A colleague brought my attention to this brain-teaser, from <a href="http://projecteuler.net/">Project Euler</a>:</p>
<div style="border-bottom:black 1px dotted;border-left:black 1px dotted;background-color:#f0f0f0;float:left;margin-left:2em;border-top:black 1px dotted;margin-right:auto;border-right:black 1px dotted;margin-bottom:.5em;padding:.5em .5em 0;">
<p>The series, 1<sup>1</sup> + 2<sup>2</sup> + 3<sup>3</sup> + 4<sup>4</sup> + … + 10<sup>10</sup> = 10405071317.</p>
<p>Find the last ten digits of the series, 1<sup>1</sup> + 2<sup>2</sup> + 3<sup>3</sup> + 4<sup>4</sup> + … + 1000<sup>1000</sup></p>
</p></div>
<p style="clear:left;">Having a Unix background, my first instinct was to fire up <a href="http://directory.fsf.org/project/bc/">bc</a> which I know can deal with integers of any size you like—such a calculator is known as an arbitrary precision calculator.</p>
<p style="clear:left;">Here’s the one-liner, together with execution time:</p>
<p style="clear:left;"><a href="http://skepticabin.files.wordpress.com/2009/05/image.png"><img style="display:block;float:none;margin-left:auto;margin-right:auto;border-width:0;" title="image" border="0" alt="image" src="http://skepticabin.files.wordpress.com/2009/05/image_thumb.png?w=588&#038;h=91" width="588" height="91" /></a> </p>
<p style="clear:left;">Now, if you’re a Java programmer, you’ll know about <a href="http://java.sun.com/javase/6/docs/api/java/math/BigInteger.html">java.math.BigInteger</a> which is the implementation of an arbitrary precision integer.&#160; Sadly, in the .NET world there is no built-in equivalent (<a href="http://blogs.msdn.com/bclteam/archive/2008/11/04/what-s-new-in-the-bcl-in-net-4-0-justin-van-patten.aspx">soon to change in .NET 4.0</a>).</p>
<p style="clear:left;">What I did find interesting though was that the default (and only) implementation of integer in a lot of languages, including Python and Ruby is of the arbitrary precision variety (this also applies to Scheme and Lisp).&#160; Since I have two implementations of python installed on my PC, namely <a href="http://en.wikipedia.org/wiki/CPython">cpython</a> and <a href="http://www.codeplex.com/Wiki/View.aspx?ProjectName=IronPython">IronPython</a>, I could benchmark them from the command line.</p>
<p style="clear:left;">First, cpython: <a href="http://skepticabin.files.wordpress.com/2009/05/image1.png"><img style="display:block;float:none;border-width:0;margin:10px auto;" title="image" border="0" alt="image" src="http://skepticabin.files.wordpress.com/2009/05/image_thumb1.png?w=581&#038;h=87" width="581" height="87" /></a> And … IronPython:</p>
<p style="clear:left;"><a href="http://skepticabin.files.wordpress.com/2009/05/image2.png"><img style="display:block;float:none;border-width:0;margin:0 auto 5px;" title="image" border="0" alt="image" src="http://skepticabin.files.wordpress.com/2009/05/image2.png?w=584&#038;h=88" width="584" height="88" /></a>Unfortunately the initialisation of the python runtime puts a nasty skew on our comparison in the case of IronPython.</p>
<p style="clear:left;">Somehow, that just feels like cheating though, and even though there aren’t any set rules on Project Euler about how you come to the answer, of course, you just feel like you should be doing it a clever way; read: no use of a big integer library, built-in or otherwise.</p>
<p style="clear:left;">The solution is simple, but deceptively so—why would we need to keep track of all those “more significant digits” if we never need them?&#160; As long as we keep our eight byte integer from overflowing, we should be fine.&#160; Hence our BigInteger-free C# version:</p>
<p><pre class="brush: csharp;">
class Program 
{
    static void Main(string[] args)
    { 
        var largest = 10L*10*10*10*10*10*10*10*10*10; 
        var tot = 0L; 
        for (int i = 1; i &lt; 1001; i++)
        { 
            var exp = 1L; 
            for (int j = 0; j &lt; i; j++)
                exp = (exp * i) % largest;
            tot = (tot + exp) % largest;
        }
        Console.WriteLine(tot);
    } 
}
</pre>
<p>And the result:</p>
<p><a href="http://skepticabin.files.wordpress.com/2009/05/image3.png"><img style="display:block;float:none;margin-left:auto;margin-right:auto;border-width:0;" title="image" border="0" alt="image" src="http://skepticabin.files.wordpress.com/2009/05/image_thumb3.png?w=594&#038;h=86" width="594" height="86" /></a></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/skepticabin.wordpress.com/142/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/skepticabin.wordpress.com/142/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/skepticabin.wordpress.com/142/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/skepticabin.wordpress.com/142/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/skepticabin.wordpress.com/142/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/skepticabin.wordpress.com/142/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/skepticabin.wordpress.com/142/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/skepticabin.wordpress.com/142/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/skepticabin.wordpress.com/142/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/skepticabin.wordpress.com/142/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/skepticabin.wordpress.com/142/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/skepticabin.wordpress.com/142/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/skepticabin.wordpress.com/142/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/skepticabin.wordpress.com/142/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=thelimberlambda.com&amp;blog=2436519&amp;post=142&amp;subd=skepticabin&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://thelimberlambda.com/2009/05/12/sharpen-up-series-episode-6/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/b4cf8c0d26636bfbef4bcba057b27f01?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Serfsmith</media:title>
		</media:content>

		<media:content url="http://skepticabin.files.wordpress.com/2009/05/image_thumb.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>

		<media:content url="http://skepticabin.files.wordpress.com/2009/05/image_thumb1.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>

		<media:content url="http://skepticabin.files.wordpress.com/2009/05/image2.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>

		<media:content url="http://skepticabin.files.wordpress.com/2009/05/image_thumb3.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>
	</item>
		<item>
		<title>&#8220;Sharpen Up&#8221; Series: Episode 5</title>
		<link>http://thelimberlambda.com/2008/11/20/sharpen-up-series-episode-5/</link>
		<comments>http://thelimberlambda.com/2008/11/20/sharpen-up-series-episode-5/#comments</comments>
		<pubDate>Thu, 20 Nov 2008 17:33:43 +0000</pubDate>
		<dc:creator>Eric Smith</dc:creator>
				<category><![CDATA[Fun]]></category>
		<category><![CDATA[pi]]></category>

		<guid isPermaLink="false">http://skepticabin.wordpress.com/?p=91</guid>
		<description><![CDATA[This one got me thinking for a long time, mostly because I subconsciously eliminated &#8220;cheat&#8221; solutions.  The problem is to calculate an estimate of π by working out the perimeter of an n-sided circle-inscribing polygon.  Let&#8217;s start with some pictures: Now, the obvious solution (focus on Figure A) is to use a trigonmetric function to [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=thelimberlambda.com&amp;blog=2436519&amp;post=91&amp;subd=skepticabin&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>This one got me thinking for a long time, mostly because I subconsciously eliminated &#8220;cheat&#8221; solutions.  The problem is to calculate an estimate of π by working out the perimeter of an n-sided circle-inscribing polygon.  Let&#8217;s start with some pictures:</p>
<p><a href="http://skepticabin.files.wordpress.com/2008/11/circle.png"><img style="border:#ffffff;" title="circle" src="http://skepticabin.files.wordpress.com/2008/11/circle.png?w=700"></a></p>
<p>Now, the obvious solution (focus on Figure A) is to use a trigonmetric function to solve the problem.  Using a convenient r = 0.5 (implies that the perimeter of the circle is π) one side of our polygon (d) can be determined as follows:</p>
<p style="text-align:center;"><strong>d = 2r<em>sin </em>θ</strong></p>
<p>And since the perimeter of the polygon = p = <em>nd</em>, and r = 0.5, and θ = 2π/2n, then:</p>
<p style="text-align:center;"><strong>p = n<em>sin </em>(</strong>π<strong>/n)</strong></p>
<p style="text-align:left;">All too easy, and well &#8230; we&#8217;re using π to find an approximation of π.  Somehow that doesn&#8217;t sit well with me.  Which is the reason why I took two days to come up with a solution that <em>didn&#8217;t</em> involve trigonometric functions, or π.  Enter Figure B.</p>
<p style="text-align:left;">We apply a method of virtual construction&#8211;let&#8217;s assume a cartesian plane, our circle having centre (0,0), and radius r = 0.5.  The method is iterative, so we&#8217;ll need to start with a guess of the length of a side of the polygon, R<sub>guess</sub> =P<sub>guess</sub> / n, where P<sub>guess</sub> is our &#8220;perimeter guess&#8221;.  P<sub>guess</sub> can&#8217;t be any larger than π, so let&#8217;s make the upper bound = 3.2.  R<sub>guess</sub> then forms the radius of a &#8220;construction circle&#8221;, with centre (x,y), starting at (x<sub>0</sub>,y<sub>0</sub>) in the diagram.  The intersection of said construction circle and our original circle will determine a polygon corner; of course, since there are two intersection points, we eliminate the one that has already been &#8220;visited&#8221; (or occurs where y is negative in the case of the first attempt).  We progressively &#8220;construct&#8221; our way around the circle n times, each time using the previously determined &#8220;corner&#8221; as the centre of the next construction circle, finally arriving at the final intersection point: (x<sub>n</sub>, y<sub>n</sub>).  If R<sub>guess</sub> was correct, then (x<sub>n</sub>, y<sub>n</sub>) would equal (x<sub>0</sub>,y<sub>0</sub>).  Adjusting R<sub>guess</sub> for the next iteration then becomes a case of increasing P<sub>guess</sub> if y<sub>n</sub> turned out negative and decreasing P<sub>guess</sub> if y<sub>n</sub> turned out positive.  A simple zero-by-halving (aka <a href="http://en.wikipedia.org/wiki/Bisection_method">Bisection</a>) technique is employed to get a value for the perimeter that satisfies the accuracy constraint (1e-9).</p>
<p style="text-align:left;">The source code for my π-less solution is below:</p>
<p style="text-align:left;">
<p><pre class="brush: csharp;">

using System;

class Archimedes
{
    public double approximatePi(int numSides)
    {
        double upperPi = 3.5;
        double lowerPi = 0.0;
        while (Math.Abs(upperPi - lowerPi) &gt; 1e-10)
        {
            bool first = true;
            double cx = 0.5;
            double cy = 0.0;
            double piGuess = (upperPi + lowerPi) / 2;
            double lastCx = 0.0, lastCy = 0.0;
            for (int i = 0; i &lt; numSides; i++)
            {
                double[][] intersections = GetCirclesIntersection(cx, cy, piGuess, numSides);
                if (intersections[0][0] == Double.NaN ||
                    intersections[0][1] == Double.NaN ||
                    intersections[1][0] == Double.NaN ||
                    intersections[1][1] == Double.NaN)
                {
                    cy = 1;
                    break;
                }
                if (first)
                {
                    if (intersections[0][1] &gt; 0)
                    {
                        lastCx = cx;
                        lastCy = cy;
                        cx = intersections[0][0];
                        cy = intersections[0][1];
                    }
                    else
                    {
                        lastCx = cx;
                        lastCy = cy;
                        cx = intersections[1][0];
                        cy = intersections[1][1];
                    }
                    first = false;
                }
                else
                {
                    if (Math.Abs(intersections[0][0] - lastCx) &lt; 1e-10 &amp;&amp;
                        Math.Abs(intersections[0][1] - lastCy) &lt; 1e-10)
                    {
                        lastCx = cx;
                        lastCy = cy;
                        cx = intersections[1][0];
                        cy = intersections[1][1];
                    }
                    else
                    {
                        lastCx = cx;
                        lastCy = cy;
                        cx = intersections[0][0];
                        cy = intersections[0][1];
                    }
                }
            }
            if (cy &lt; 0.0)
            {
                lowerPi = piGuess;
            }
            else
            {
                upperPi = piGuess;
            }
        }
        return upperPi;
    }

    private double[][] GetCirclesIntersection(double xo, double yo, double piGuess, int n)
    {
        double e = xo;
        double f = yo;
        double p = Math.Sqrt(e*e + f*f);
        double k = (p * p + 0.25 - (piGuess / n) * (piGuess / n)) / (2 * p);
        return new double[2][] {
            new double[] {
                (e*k)/p + (f/p) * Math.Sqrt(0.25-k*k),
                (f*k)/p - (e/p) * Math.Sqrt(0.25-k*k) },
            new double[] {
                (e*k)/p - (f/p) * Math.Sqrt(0.25-k*k),
                (f*k)/p + (e/p) * Math.Sqrt(0.25-k*k)
            }
        };
    }
}

</pre></p>
<p style="text-align:left;">
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/skepticabin.wordpress.com/91/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/skepticabin.wordpress.com/91/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/skepticabin.wordpress.com/91/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/skepticabin.wordpress.com/91/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/skepticabin.wordpress.com/91/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/skepticabin.wordpress.com/91/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/skepticabin.wordpress.com/91/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/skepticabin.wordpress.com/91/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/skepticabin.wordpress.com/91/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/skepticabin.wordpress.com/91/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/skepticabin.wordpress.com/91/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/skepticabin.wordpress.com/91/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/skepticabin.wordpress.com/91/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/skepticabin.wordpress.com/91/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=thelimberlambda.com&amp;blog=2436519&amp;post=91&amp;subd=skepticabin&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://thelimberlambda.com/2008/11/20/sharpen-up-series-episode-5/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/b4cf8c0d26636bfbef4bcba057b27f01?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Serfsmith</media:title>
		</media:content>

		<media:content url="http://skepticabin.files.wordpress.com/2008/11/circle.png" medium="image">
			<media:title type="html">circle</media:title>
		</media:content>
	</item>
		<item>
		<title>&#8220;Sharpen Up&#8221; Series: Episode 4</title>
		<link>http://thelimberlambda.com/2008/11/07/sharpen-up-series-episode-4/</link>
		<comments>http://thelimberlambda.com/2008/11/07/sharpen-up-series-episode-4/#comments</comments>
		<pubDate>Fri, 07 Nov 2008 14:20:44 +0000</pubDate>
		<dc:creator>Eric Smith</dc:creator>
				<category><![CDATA[Fun]]></category>

		<guid isPermaLink="false">http://skepticabin.wordpress.com/?p=89</guid>
		<description><![CDATA[Continuing my &#8220;Sharpen Up&#8221; Series, herewith the next episode. The problem is to find digits that: For an integer n, divide exactly into n; Also divide exactly into the sum of the digits of n. For example, 3 divides exactly into 81 and also divides exactly into 8+1 = 9.  Except that the problem gets [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=thelimberlambda.com&amp;blog=2436519&amp;post=89&amp;subd=skepticabin&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Continuing my &#8220;Sharpen Up&#8221; Series, herewith the next episode.</p>
<p>The problem is to find digits that:</p>
<ol>
<li>For an integer <em>n</em>, divide exactly into <em>n</em>;</li>
<li><em>Also</em> divide exactly into the sum of the digits of <em>n.</em></li>
</ol>
<p>For example, 3 divides exactly into 81 and <em>also</em> divides exactly into 8+1 = 9.  Except that the problem gets harder&#8211;there&#8217;s a requirement to <em>count</em> the digits for a particular <em>base</em> numbering system for which this property holds.  Using base 10, only 3 and 9 satisfy this property.  The problem statement indicates that if a digit appears to be a candidate for all possible numbers with less than 4 digits of the relevant base, then it is deemed true for all numbers.  The trivial cases of 0 and 1 should not be included in the count.</p>
<p>This problem took me 36 minutes to complete&#8211;here&#8217;s my solution:</p>
<p><pre class="brush: csharp;">

using System.Collections.Generic;

// 4:30
// 5:06
// SRM150DIV1_250
public class InterestingDigits
{
    private int[] num = new int[3];

    public int[] digits(int Base)
    {
        List&lt;int&gt; interesting = new List&lt;int&gt;();
        for (int d = 2; d &lt; Base; d++)
        {
            for (int i = 0; i &lt; 3; i++)
                num[i] = 0;
            num[0] = d;
            bool exception = false;
            while (true)
            {
                if (((num[0] + num[1] + num[2]) % d == 0 &amp;&amp; 
                     (num[0] + num[1]*Base + num[2]*Base*Base) % d != 0) ||
                    ((num[0] + num[1] + num[2]) % d != 0 &amp;&amp; 
                     (num[0] + num[1]*Base + num[2]*Base*Base) % d == 0))
                {
                    exception = true;
                    break;
                }
                if (++num[0] == Base)
                {
                    num[0] = 0;
                    if (++num[1] == Base)
                    {
                        num[1] = 0;
                        if (++num[2] == Base)
                        {
                            break;
                        }
                    }
                }
            }
            if (!exception)
            {
                interesting.Add(d);
            }
        }
        return interesting.ToArray();
    }
}

</pre></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/skepticabin.wordpress.com/89/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/skepticabin.wordpress.com/89/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/skepticabin.wordpress.com/89/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/skepticabin.wordpress.com/89/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/skepticabin.wordpress.com/89/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/skepticabin.wordpress.com/89/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/skepticabin.wordpress.com/89/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/skepticabin.wordpress.com/89/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/skepticabin.wordpress.com/89/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/skepticabin.wordpress.com/89/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/skepticabin.wordpress.com/89/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/skepticabin.wordpress.com/89/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/skepticabin.wordpress.com/89/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/skepticabin.wordpress.com/89/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=thelimberlambda.com&amp;blog=2436519&amp;post=89&amp;subd=skepticabin&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://thelimberlambda.com/2008/11/07/sharpen-up-series-episode-4/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/b4cf8c0d26636bfbef4bcba057b27f01?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Serfsmith</media:title>
		</media:content>
	</item>
		<item>
		<title>&#8220;Sharpened Up&#8221;: Episode 3 Optimised</title>
		<link>http://thelimberlambda.com/2008/11/06/sharpened-up-episode-3-optimised/</link>
		<comments>http://thelimberlambda.com/2008/11/06/sharpened-up-episode-3-optimised/#comments</comments>
		<pubDate>Thu, 06 Nov 2008 06:10:26 +0000</pubDate>
		<dc:creator>Eric Smith</dc:creator>
				<category><![CDATA[Fun]]></category>

		<guid isPermaLink="false">http://skepticabin.wordpress.com/?p=87</guid>
		<description><![CDATA[Lesson learned&#8211;there&#8217;s a way of approaching TopCoder problems, and speeding through the problem description (missing some important, sometimes subtle hints as you go) is not the way.  Give yourself some time, maybe pull out a pencil and paper, doodle a bit, let your mind free.  Only then do you avail yourself of that light-bulb moment. [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=thelimberlambda.com&amp;blog=2436519&amp;post=87&amp;subd=skepticabin&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Lesson learned&#8211;there&#8217;s a way of approaching TopCoder problems, and speeding through the problem description (missing some important, sometimes subtle hints as you go) is not the way.  Give yourself some time, maybe pull out a pencil and paper, doodle a bit, let your mind free.  Only then do you avail yourself of that light-bulb moment.</p>
<p>So, it turns out that the fast-food joint problem really isn&#8217;t that hard at all.  In a nutshell the time that a customer waits can be summed up as follows:</p>
<p><strong>Wait<sub>n</sub> = Arrival<sub>0</sub> &#8211; Arrival<sub>n</sub> + Wait<sub>n-1</sub> + Service<sub>n-1</sub></strong></p>
<p>&#8230; but only if <strong>Arrival<sub>0</sub> + (Wait<sub>n-1</sub> + Service<sub>n-1</sub>)</strong> is <em>later than </em>(greater than) <strong>Arrival<sub>n</sub></strong>, otherwise <strong>Wait<sub>n</sub> = 0</strong></p>
<p>&#8230; and of course, <strong>Wait<sub>0</sub> = 0</strong></p>
<p>That&#8217;s it&#8211;here&#8217;s the source:</p>
<p><pre class="brush: csharp;">

public class BigBurger
{
    private int _MaxWait = 0;

    public int maxWait(int[] arrival, int[] service)
    {
        _MaxWait = 0;
        WaitFor(arrival, service, arrival.Length-1);
        return _MaxWait;
    }

    private int WaitFor(int[] arrival, int[] service, int ix)
    {
        if (ix == 0)
            return 0;
        int w = WaitFor(arrival, service, ix - 1) + service[ix - 1];
        w = (arrival[0] + w) &gt; arrival[ix] ? arrival[0] + w - arrival[ix] : 0;
        _MaxWait = _MaxWait &lt; w ? w : _MaxWait;
        return w;
    }
}

</pre></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/skepticabin.wordpress.com/87/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/skepticabin.wordpress.com/87/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/skepticabin.wordpress.com/87/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/skepticabin.wordpress.com/87/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/skepticabin.wordpress.com/87/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/skepticabin.wordpress.com/87/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/skepticabin.wordpress.com/87/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/skepticabin.wordpress.com/87/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/skepticabin.wordpress.com/87/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/skepticabin.wordpress.com/87/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/skepticabin.wordpress.com/87/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/skepticabin.wordpress.com/87/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/skepticabin.wordpress.com/87/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/skepticabin.wordpress.com/87/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=thelimberlambda.com&amp;blog=2436519&amp;post=87&amp;subd=skepticabin&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://thelimberlambda.com/2008/11/06/sharpened-up-episode-3-optimised/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/b4cf8c0d26636bfbef4bcba057b27f01?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Serfsmith</media:title>
		</media:content>
	</item>
		<item>
		<title>&#8220;Sharpen Up&#8221; Series: Episode 3</title>
		<link>http://thelimberlambda.com/2008/11/05/sharpen-up-series-episode-3/</link>
		<comments>http://thelimberlambda.com/2008/11/05/sharpen-up-series-episode-3/#comments</comments>
		<pubDate>Wed, 05 Nov 2008 18:03:27 +0000</pubDate>
		<dc:creator>Eric Smith</dc:creator>
				<category><![CDATA[Fun]]></category>

		<guid isPermaLink="false">http://skepticabin.wordpress.com/?p=83</guid>
		<description><![CDATA[This is officially horribly embarrassing: 86 out of 250 points, and 1.5 hours later.  I simply could not get my mind around this one and out of sheer frustration ended up simulating the scenario (no doubt the most suboptimal solution) in painstaking detail. This fast food joint has a queue (as they do), and a [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=thelimberlambda.com&amp;blog=2436519&amp;post=83&amp;subd=skepticabin&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>This is officially horribly embarrassing: 86 out of 250 points, and 1.5 hours later.  I simply could not get my mind around this one and out of sheer frustration ended up simulating the scenario (no doubt the most suboptimal solution) in painstaking detail.</p>
<p>This fast food joint has a queue (as they do), and a bunch of people arrive at integer value times provided in an array.  Congruent to this array is an array of integer durations of the same units indicating the time taken to serve the customer.  So if we have arrival = [1, 2, 3] and service = [10, 2, 10] then there are three customers, each arriving at time 1, 2 and 3 respectively; customer 1 has to wait 10 minutes for his order, customer 2, 2 minutes and customer 3, 10 minutes.  If consecutive customers arrive at the same time, they should be dealt with in the order in which they are encountered in the array.  The arrivals values will always be in non-descending order, and there won&#8217;t ever be a (fictitious) service of 0 minutes.  So, find the maximum time any one customer needs to wait to <em>get to order</em>.</p>
<p>It occurred to me that all of this isn&#8217;t very much help for anyone who chooses to try these problems themselves without benchmark input values and corresponding answers.  Here are the ones I worked against: {3, 3, 9} {2, 15, 14} = 11, {182} {11} = 0, {2,10,11} {3, 4, 3} = 3, {2,10,12} {15,1,15} = 7.</p>
<p>&#8230; and here&#8217;s my solution:</p>
<p><pre class="brush: csharp;">

using System.Collections.Generic;

public class BigBurger
{
    public int maxWait(int[] arrival, int[] service)
    {
        int[] waitingTime = new int[arrival.Length];
        Queue&lt;int&gt; queue = new Queue&lt;int&gt;();
        int maxwait = 0;
        int index = 0;
        int time = 0;
        int lastStart = 0;
        bool started = false;
        while (queue.Count &gt; 0 | !started | index &lt; arrival.Length)
        {
            time++;
            foreach (int v in queue)
            {
                waitingTime[v]++;
            }
            if (queue.Count &gt; 0 &amp;&amp; (time - lastStart) &gt;= service[queue.Peek()])
            {
                queue.Dequeue();
                lastStart = time;
                if (queue.Count == 0 &amp;&amp; index &lt; arrival.Length)
                {
                    started = false;
                }
            }
            while (index &lt; arrival.Length &amp;&amp; arrival[index] == time)
            {
                if (!started)
                {
                    lastStart = time;
                    started = true;
                }
                queue.Enqueue(index);
                index++;
            }
        }
        for (int i = 0; i &lt; waitingTime.Length; i++)
        {
            maxwait = maxwait &lt; (waitingTime[i]-service[i]) 
                ? (waitingTime[i]-service[i]) : maxwait;
        }
        return maxwait;
    }
}

</pre></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/skepticabin.wordpress.com/83/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/skepticabin.wordpress.com/83/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/skepticabin.wordpress.com/83/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/skepticabin.wordpress.com/83/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/skepticabin.wordpress.com/83/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/skepticabin.wordpress.com/83/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/skepticabin.wordpress.com/83/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/skepticabin.wordpress.com/83/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/skepticabin.wordpress.com/83/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/skepticabin.wordpress.com/83/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/skepticabin.wordpress.com/83/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/skepticabin.wordpress.com/83/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/skepticabin.wordpress.com/83/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/skepticabin.wordpress.com/83/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=thelimberlambda.com&amp;blog=2436519&amp;post=83&amp;subd=skepticabin&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://thelimberlambda.com/2008/11/05/sharpen-up-series-episode-3/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/b4cf8c0d26636bfbef4bcba057b27f01?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Serfsmith</media:title>
		</media:content>
	</item>
		<item>
		<title>&#8220;Sharpen Up&#8221; Series: Episode 2</title>
		<link>http://thelimberlambda.com/2008/11/05/sharpen-up-series-episode-2/</link>
		<comments>http://thelimberlambda.com/2008/11/05/sharpen-up-series-episode-2/#comments</comments>
		<pubDate>Wed, 05 Nov 2008 16:05:23 +0000</pubDate>
		<dc:creator>Eric Smith</dc:creator>
				<category><![CDATA[Fun]]></category>

		<guid isPermaLink="false">http://skepticabin.wordpress.com/?p=79</guid>
		<description><![CDATA[This one is an example of &#8220;trivial&#8221;.  Problem description: find how many digits in a given number divide evenly into the number.  This took me around about 2 minutes for a whopping 239 points out of 250.  My solution:<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=thelimberlambda.com&amp;blog=2436519&amp;post=79&amp;subd=skepticabin&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>This one is an example of &#8220;trivial&#8221;.  Problem description: find how many digits in a given number divide <em>evenly</em> into the number.  This took me around about 2 minutes for a whopping 239 points out of 250.  My solution:</p>
<p><pre class="brush: csharp;">
public class DivisorDigits
{
	public int howMany(int number)
	{
		int count = 0;
		foreach (char c in number.ToString())
		{
			if (c == '0')
				continue;
			if (number % (c - '0') == 0)
			{
				count++;
			}
		}
		return count;
	}
}
</pre></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/skepticabin.wordpress.com/79/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/skepticabin.wordpress.com/79/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/skepticabin.wordpress.com/79/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/skepticabin.wordpress.com/79/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/skepticabin.wordpress.com/79/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/skepticabin.wordpress.com/79/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/skepticabin.wordpress.com/79/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/skepticabin.wordpress.com/79/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/skepticabin.wordpress.com/79/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/skepticabin.wordpress.com/79/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/skepticabin.wordpress.com/79/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/skepticabin.wordpress.com/79/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/skepticabin.wordpress.com/79/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/skepticabin.wordpress.com/79/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=thelimberlambda.com&amp;blog=2436519&amp;post=79&amp;subd=skepticabin&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://thelimberlambda.com/2008/11/05/sharpen-up-series-episode-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/b4cf8c0d26636bfbef4bcba057b27f01?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Serfsmith</media:title>
		</media:content>
	</item>
		<item>
		<title>&#8220;Sharpen Up&#8221; Series: Episode 1</title>
		<link>http://thelimberlambda.com/2008/11/05/sharpen-up-series-episode-1/</link>
		<comments>http://thelimberlambda.com/2008/11/05/sharpen-up-series-episode-1/#comments</comments>
		<pubDate>Wed, 05 Nov 2008 15:42:35 +0000</pubDate>
		<dc:creator>Eric Smith</dc:creator>
				<category><![CDATA[Fun]]></category>

		<guid isPermaLink="false">http://skepticabin.wordpress.com/?p=75</guid>
		<description><![CDATA[In an attempt to stay &#8220;Ninja sharp&#8221; on the coding front, I&#8217;ve committed to solving a TopCoder problem from time to time.  This is really just a self-improvement effort, and I don&#8217;t intend to take on the cream-of-coding at TC anytime soon.  Having dipped my pinky toe in the water I have to say that [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=thelimberlambda.com&amp;blog=2436519&amp;post=75&amp;subd=skepticabin&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>In an attempt to stay &#8220;Ninja sharp&#8221; on the coding front, I&#8217;ve committed to solving a <a href="http://www.topcoder.com/">TopCoder</a> problem from time to time.  This is really just a self-improvement effort, and I don&#8217;t intend to take on the cream-of-coding at TC anytime soon.  Having dipped my pinky toe in the water I have to say that (in my oh-so humble opinion) the standard is somewhat high.  In every practice room there are three problems: &#8220;easy&#8221;, &#8220;medium&#8221; and &#8220;hard&#8221; respectively based on the maximum points that can be awarded.  The point system is a little obscure, but what I have determined is that the points you can earn is exclusively determined by the time taken to complete the problem.  The relationship is non-linear and although I haven&#8217;t dug into the details, I&#8217;m assuming asymptotic with some minimum value.  That is, your points seem to fall off quickly but gradually level out until you can&#8217;t &#8220;lose&#8221; any more.  So far, I&#8217;ve concentrated on &#8220;easy&#8221; and although some problems can be safely lumped in the &#8220;trivial&#8221; category, others are deceptively difficult.</p>
<p>Given the one-and-only criterion for success, one is quickly honed into punching out working code as quickly as possible.  Coding standards and niceties go out the window&#8211;faster is better and style counts for nothing.  Each problem can be coded in one of three languages, viz., C++, Java or C# (some problems have a &#8220;Python&#8221; as well, but it&#8217;s greyed out&#8211;possible future functionality?); erm &#8230; that would be C# 2.0, no thumping the competition with a quick lambda expression and a couple of extension methods.</p>
<p>For the sake of reference (and of course discussion), I&#8217;m going to post my solutions and the time taken to complete them (give or take a few minutes due to distractions) as episodes.  TC no doubt are ready to disembowel your children should you cut-and-paste their problem descriptions, so I will provide a paraphrasing in each case.</p>
<p>Episode 1 involves a fictitious pack of cards.  TC have made a noble effort to keep their problems real-world whilst still making them challenging&#8211;never-the-less I have to admit that they can sometimes be a little contrived.  So &#8230; there&#8217;s this pack of cards containing an arbitrary number of cards.  The cards in the pack are represented by characters in a string.  The cards have values &#8217;0&#8242; to &#8217;9&#8242;, &#8216;A&#8217; = 1, &#8216;T&#8217; = 10, &#8216;J&#8217;, &#8216;Q&#8217; and &#8216;K&#8217; = 11, 12 and 13 respectively.  The rules are: go through the pack, removing all &#8216;K&#8217;s, and removing all consecutive pairs of cards whose total value equals 13, repeating the cycle as needs be and finally return the number of cards remaining when you can no longer remove any cards.  Not hard, but a little tricky&#8211;this particular problem, if solved in an insanely short amount of time gets you 250 points.  I left it for a day and got 75&#8230; The plan is to actually be rigorous about timing myself, making sure that I do this when I won&#8217;t be interrupted.  That&#8217;s for the future.</p>
<p>Here&#8217;s my solution:</p>
<p><pre class="brush: csharp;">

public class CircleGame
{
    public int cardsLeft(string deck)
    {
        char[] work = new char[deck.Length];
        for (int i = 0; i &lt; deck.Length; i++)
        {
            work[i] = deck[i];
        }
        int lastix = -1;
        int loops = 0;
        int count = 0;
        while (loops &lt; 3)
        {
            int countstart = count;
            for (int i = 0; i &lt; work.Length; i++)
            {
                if (work[i] == 'K')
                {
                    work[i] = '.';
                    count++;
                    continue;
                }
                if (work[i] == '.')
                {
                    continue;
                }
                if (lastix == -1)
                {
                    lastix = i;
                    continue;
                }
                if (val(work[lastix]) + val(work[i]) == 13)
                {
                    work[i] = '.';
                    work[lastix] = '.';
                    lastix = -1;
                    count += 2;
                    continue;
                }
                lastix = i;
            }
            if (countstart == count)
                loops++;
            else
                loops = 0;
        }
        return deck.Length - count;
    }

    private int val(char c)
    {
        if (c &gt;= '0' &amp;&amp; c &lt;= '9')
        {
            return (int)(c - '0');
        }
        if (c == 'T')
            return 10;
        if (c == 'J')
            return 11;
        if (c == 'Q')
            return 12;
        if (c == 'A')
            return 1;
        return 13;
    }
}

</pre></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/skepticabin.wordpress.com/75/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/skepticabin.wordpress.com/75/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/skepticabin.wordpress.com/75/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/skepticabin.wordpress.com/75/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/skepticabin.wordpress.com/75/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/skepticabin.wordpress.com/75/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/skepticabin.wordpress.com/75/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/skepticabin.wordpress.com/75/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/skepticabin.wordpress.com/75/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/skepticabin.wordpress.com/75/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/skepticabin.wordpress.com/75/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/skepticabin.wordpress.com/75/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/skepticabin.wordpress.com/75/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/skepticabin.wordpress.com/75/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=thelimberlambda.com&amp;blog=2436519&amp;post=75&amp;subd=skepticabin&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://thelimberlambda.com/2008/11/05/sharpen-up-series-episode-1/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/b4cf8c0d26636bfbef4bcba057b27f01?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Serfsmith</media:title>
		</media:content>
	</item>
		<item>
		<title>Delegate Magic</title>
		<link>http://thelimberlambda.com/2008/10/13/delegate-magic/</link>
		<comments>http://thelimberlambda.com/2008/10/13/delegate-magic/#comments</comments>
		<pubDate>Mon, 13 Oct 2008 05:48:23 +0000</pubDate>
		<dc:creator>Eric Smith</dc:creator>
				<category><![CDATA[Fun]]></category>
		<category><![CDATA[c#]]></category>
		<category><![CDATA[closures]]></category>
		<category><![CDATA[delegates]]></category>

		<guid isPermaLink="false">http://skepticabin.wordpress.com/?p=55</guid>
		<description><![CDATA[So, you&#8217;ve used delegates with gay abandon and everything just seems to work.  In particular, this sort of thing works without a hitch: I&#8217;m referring, of course, to the bit that returns a delegate that references a method variable. I&#8217;ve always been curious as to how that works, so I dug into the IL to [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=thelimberlambda.com&amp;blog=2436519&amp;post=55&amp;subd=skepticabin&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>So, you&#8217;ve used delegates with gay abandon and everything just seems to work.  In particular, this sort of thing works without a hitch:</p>
<p><pre class="brush: csharp;">
	class Proggy
	{
		public static void Main(string[] args)
		{
			var p = new Proggy();
			Console.WriteLine(p.StuffThatNeedsDoing()());
			Console.ReadLine();
		}

		public Func&lt;int&gt; StuffThatNeedsDoing()
		{
			var ia = new int[1];
			ia[0] = 2;
			return (() =&gt; ia[0] * ia[0]);
		}
	}
</pre></p>
<p>I&#8217;m referring, of course, to the bit that returns a delegate that references a method variable.  I&#8217;ve always been curious as to how that works, so I dug into the IL to reveal the magic.</p>
<p>The interesting bit is the implementation of <code>StuffThatNeedsDoing()</code>:</p>
<p><a href="http://skepticabin.files.wordpress.com/2008/10/stuffthatneedsdoing.jpg"><img class="alignnone size-full wp-image-57" title="stuffthatneedsdoing" src="http://skepticabin.files.wordpress.com/2008/10/stuffthatneedsdoing.jpg?w=700&#038;h=365" alt="" width="700" height="365" /></a></p>
<p>Let&#8217;s take a closer look as to what is happening here:</p>
<ul>
<li>Behind the scenes, the compiler generates a nested class called <code>&lt;&gt;c__DisplayClass1</code><br />
and encapsulates our <code>int[]</code> in it.</li>
<li><code>L_0000</code> to <code>L_000e</code> news up an instance of <code>&lt;&gt;c__DisplayClass1</code> and assigns the <code>ia</code> field therein to a new <code>int[]</code> of size 1.</li>
<li><code>L_0013</code> to <code>L_001b</code> assigns the value 2 to element 0 of <code>ia</code> within the instance.</li>
<li><code>L_001c</code> to <code>L_0028</code> news up a <code>Func&lt;int&gt;</code>, passing to the constructor the reference to <code>&lt;&gt;c__DisplayClass1</code> and the address of a method on <code>&lt;&gt;c__DisplayClass1</code> called <code>&lt;StuffThatNeedsDoing&gt;b__0</code> (which turns out to be our delegate implementation).</li>
<li>The new <code>Func&lt;int&gt;</code> is then effectively returned.</li>
</ul>
<p>In short &#8211; it looks (unsurprisingly) like the local <code>ia</code> is no longer a local, and naively referencing it from within the delegate has caused it to be treated like a heap variable.  Of course our &#8220;local&#8221; ia now has a lifetime consistent with the lifetime of the delegate returned by <code>StuffThatNeedsDoing</code>&#8212;not a problem if we don&#8217;t mind, but what if we had referenced a &#8220;local&#8221; <code>IDataReader</code> from within our delegate?  The <code>IDataReader</code>, and associated unmanaged resources, would lurk around possibly for a very long time &#8230; something to be aware of.</p>
<p>So, as it turns out, the thing that binds a function to it&#8217;s &#8220;environment&#8221; (in this case, the local that we referenced) is known as a <a href="http://en.wikipedia.org/wiki/Closure_(computer_science)">closure</a>.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/skepticabin.wordpress.com/55/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/skepticabin.wordpress.com/55/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/skepticabin.wordpress.com/55/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/skepticabin.wordpress.com/55/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/skepticabin.wordpress.com/55/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/skepticabin.wordpress.com/55/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/skepticabin.wordpress.com/55/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/skepticabin.wordpress.com/55/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/skepticabin.wordpress.com/55/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/skepticabin.wordpress.com/55/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/skepticabin.wordpress.com/55/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/skepticabin.wordpress.com/55/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/skepticabin.wordpress.com/55/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/skepticabin.wordpress.com/55/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=thelimberlambda.com&amp;blog=2436519&amp;post=55&amp;subd=skepticabin&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://thelimberlambda.com/2008/10/13/delegate-magic/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/b4cf8c0d26636bfbef4bcba057b27f01?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Serfsmith</media:title>
		</media:content>

		<media:content url="http://skepticabin.files.wordpress.com/2008/10/stuffthatneedsdoing.jpg" medium="image">
			<media:title type="html">stuffthatneedsdoing</media:title>
		</media:content>
	</item>
	</channel>
</rss>
