<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xml:base="http://thesamovar.net" xmlns:dc="http://purl.org/dc/elements/1.1/">
<channel>
 <title>Programming</title>
 <link>http://thesamovar.net/taxonomy/term/5/feed</link>
 <description>The taxonomy view with a depth of 0.</description>
 <language>en</language>
<item>
 <title>Countdown numbers game solver</title>
 <link>http://thesamovar.net/countdownnumbers</link>
 <description>&lt;p&gt;While learning Python, I wrote the program attached below to solve the &lt;a href=&quot;http://www.channel4.com/entertainment/tv/microsites/C/countdown/index.html&quot;&gt;Countdown&lt;/a&gt; numbers game. From what I&amp;#39;ve seen on the web, my program is simpler than any of the other programs with source code out there. Having written it I found &lt;a href=&quot;http://www.cs.nott.ac.uk/~gmh/countdown.pdf&quot;&gt;this paper&lt;/a&gt; which uses a very similar solution to mine (but in Haskell rather than Python).&lt;/p&gt;&lt;p&gt;The source code for the first version is heavily commented with algorithmic details. It takes about 15 seconds to find all solutions on my 2.4GHz laptop.&lt;br /&gt;&lt;/p&gt;&lt;p&gt;My ideal (as always with Python) was to write a program you could just look at and understand without comments, but I don&amp;#39;t think I achieved that. The first version certainly doesn&amp;#39;t, but maybe the second version does. I&amp;#39;d be interested if a more experienced Python programmer could do better in this respect. Let me know.&lt;/p&gt; &lt;p&gt;This snippet is from the second version (slower, 40 seconds to find all solutions) which is supposed to be understandable without comments: &lt;/p&gt;&lt;pre&gt;def ValidExpressions(sources,operators=standard_operators,minimal_remaining_sources=0):&lt;br /&gt;    for value, i in zip(sources,range(len(sources))):&lt;br /&gt;        yield TerminalExpression(value=value, remaining_sources=sources[:i]+sources[i+1:])&lt;br /&gt;    if len(sources)&amp;gt;=2+minimal_remaining_sources:&lt;br /&gt;        for lhs in ValidExpressions(sources,operators,minimal_remaining_sources+1):&lt;br /&gt;            for rhs in ValidExpressions(lhs.remaining_sources, operators, minimal_remaining_sources):&lt;br /&gt;                for f in operators:&lt;br /&gt;                    try: yield BranchedExpression(operator=f, lhs=lhs, rhs=rhs, remaining_sources=rhs.remaining_sources)&lt;br /&gt;                    except InvalidExpressionError: pass&lt;br /&gt;&lt;br /&gt;def TargetExpressions(target,sources,operators=standard_operators):&lt;br /&gt;    for expression in ValidExpressions(sources,operators):&lt;br /&gt;        if expression.value==target:&lt;br /&gt;            yield expression&lt;/pre&gt; &lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;br class=&quot;clear&quot; /&gt;&lt;table id=&quot;attachments&quot;&gt;
 &lt;thead&gt;&lt;tr&gt;&lt;th&gt;Attachment&lt;/th&gt;&lt;th&gt;Size&lt;/th&gt; &lt;/tr&gt;&lt;/thead&gt;
&lt;tbody&gt;
 &lt;tr class=&quot;odd&quot;&gt;&lt;td&gt;&lt;a href=&quot;http://thesamovar.net/files/countdown-numbers-solver.py.txt&quot;&gt;countdown-numbers-solver.py.txt&lt;/a&gt;&lt;/td&gt;&lt;td&gt;8.42 KB&lt;/td&gt; &lt;/tr&gt;
 &lt;tr class=&quot;even&quot;&gt;&lt;td&gt;&lt;a href=&quot;http://thesamovar.net/files/countdown-numbers-solver-2.py.txt&quot;&gt;countdown-numbers-solver-2.py.txt&lt;/a&gt;&lt;/td&gt;&lt;td&gt;2.8 KB&lt;/td&gt; &lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
</description>
 <comments>http://thesamovar.net/countdownnumbers#comment</comments>
 <category domain="http://thesamovar.net/taxonomy/term/1">Mathematics</category>
 <category domain="http://thesamovar.net/taxonomy/term/5">Programming</category>
 <enclosure url="http://thesamovar.net/files/countdown-numbers-solver.py.txt" length="8618" type="text/plain" />
 <pubDate>Wed, 02 Jan 2008 10:44:41 +0000</pubDate>
 <dc:creator>thesamovar</dc:creator>
 <guid isPermaLink="false">85 at http://thesamovar.net</guid>
</item>
<item>
 <title>Countdown Letters ME</title>
 <link>http://thesamovar.net/countdownlettersme</link>
 <description>&lt;p&gt;Impressed by the abilities of my new mobile phone - the K750i is actually now rather old by mobile phone standards - I thought I&amp;#39;d see what I could do with J2ME (that&amp;#39;s Java for mobile phones). Thus was born the Countdown letters game solver. You enter the letters as they are read out by Carol, hit solve and in no time your phone will tell you the 5 best words you can get with those letters (and without connecting to the internet, all the data is on the phone). It takes about 10 seconds on my phone, newer phones would probably be even quicker.&lt;br /&gt;&lt;/p&gt;&lt;p&gt;You can download the JAR and JAD files at the bottom of this page. I don&amp;#39;t know about other phones, but the way you install them on my phone is:&lt;/p&gt;&lt;ol&gt;&lt;li&gt;&lt;a href=&quot;/files/countdownlettersme.jar&quot;&gt;Download the JAR file&lt;/a&gt; to your computer&lt;/li&gt;&lt;li&gt;Copy the file to the &lt;font face=&quot;courier new,courier&quot;&gt;mediafiles/other&lt;/font&gt; folder on the phone&lt;/li&gt;&lt;li&gt;Go to the &lt;font face=&quot;courier new,courier&quot;&gt;Other&lt;/font&gt; folder in the File Manager and click Install.&lt;/li&gt;&lt;li&gt;Install to &lt;font face=&quot;courier new,courier&quot;&gt;Applications&lt;/font&gt; or &lt;font face=&quot;courier new,courier&quot;&gt;Games&lt;/font&gt; as you see fit.&lt;/li&gt;&lt;li&gt;Run it, it&amp;#39;s obvious how you use it.&lt;br /&gt;&lt;/li&gt;&lt;/ol&gt;&lt;h2&gt;Technical notes &lt;/h2&gt;&lt;p&gt;I&amp;#39;ve also included the source code Java file below (rename it from &lt;font face=&quot;courier new,courier&quot;&gt;.java.txt&lt;/font&gt; to &lt;font face=&quot;courier new,courier&quot;&gt;.java&lt;/font&gt;) for anyone who might be interested.&lt;/p&gt;&lt;p&gt;I used the following code to create the &lt;font face=&quot;courier new,courier&quot;&gt;dict.dat&lt;/font&gt; file, with the longest words (9 letters) first, and then the shorter words. This is standard Java, not for the mobile phone. The file &lt;font face=&quot;courier new,courier&quot;&gt;words-small.txt&lt;/font&gt; was made from the SCOWL word list on &lt;a href=&quot;http://wordlist.sourceforge.net/&quot;&gt;Kevin&amp;#39;s Word List page&lt;/a&gt; by selecting only the English and British words and variations, not including the 80 and 95 lists (of very obscure words) to keep the file size down. On unix, you can do this quickly by putting all the lists you want to include in a specific directory, going to that directory and running &lt;font face=&quot;courier new,courier&quot;&gt;cat * &amp;gt;../words.txt&lt;/font&gt;. &lt;/p&gt;&lt;pre&gt;try {&lt;br /&gt;    // output datastream only opened once&lt;br /&gt;    File file= new File(&amp;quot;words-small.dat&amp;quot;);&lt;br /&gt;    FileOutputStream fos = new FileOutputStream(file);&lt;br /&gt;    DataOutputStream dos=new DataOutputStream(fos);&lt;br /&gt;    String str;&lt;br /&gt;    // for each word length, find all valid words of that length&lt;br /&gt;    for(int i=9;i&amp;gt;=1;i--){&lt;br /&gt;        BufferedReader in = new BufferedReader(new FileReader(&amp;quot;words-small.txt&amp;quot;));&lt;br /&gt;        while ((str = in.readLine()) != null) {&lt;br /&gt;            // is it the right length?&lt;br /&gt;            if(str.length()==i){&lt;br /&gt;                // is it valid?&lt;br /&gt;                boolean v=true;&lt;br /&gt;                for(int j=0;j&amp;lt;str.length();j++){&lt;br /&gt;                    if(str.charAt(j)&amp;lt;&amp;#39;a&amp;#39; || str.charAt(j)&amp;gt;&amp;#39;z&amp;#39;) v=false;&lt;br /&gt;                }&lt;br /&gt;                if(v) dos.writeUTF(str);&lt;br /&gt;            }&lt;br /&gt;        }&lt;br /&gt;        in.close();&lt;br /&gt;    }&lt;br /&gt;    dos.close();&lt;br /&gt;} catch (IOException e) {}&lt;/pre&gt;&lt;p&gt;Using Java DataStream files is a very efficient way to read a JAR resource file on a mobile phone, much better than reading it byte by byte and parsing into strings. The code to then find the words is basically as follows (although see the full source at the bottom of this page if you want to get it running): &lt;/p&gt;&lt;pre&gt;InputStream is = getClass().getResourceAsStream(&amp;quot;/dict.dat&amp;quot;);&lt;br /&gt;if (is == null)&lt;br /&gt;    throw new Exception(&amp;quot;File Does Not Exist&amp;quot;);&lt;br /&gt;DataInputStream dis = new DataInputStream(is);&lt;br /&gt;&lt;br /&gt;int foundwords=0;&lt;br /&gt;stringItemSolution.setText(&amp;quot;&amp;quot;); // start off with no found words, we add to this text display&lt;br /&gt;while(dis.available()&amp;gt;0 &amp;amp;&amp;amp; foundwords&amp;lt;5){&lt;br /&gt;    String s = dis.readUTF(); // read the next word from the dictionary file&lt;br /&gt;    StringBuffer lb = new StringBuffer(l); // an editable copy of the letters available&lt;br /&gt;    // can we make the string s using the letters available?&lt;br /&gt;    boolean makeable=true;&lt;br /&gt;    for(int i=0;i&amp;lt;s.length() &amp;amp;&amp;amp; makeable;i++){&lt;br /&gt;        String sc = s.substring(i,i+1); // the ith letter in the word we&amp;#39;re checking&lt;br /&gt;        int j=lb.toString().indexOf(sc); // the index of this letter in the letters still available&lt;br /&gt;        if(j&amp;gt;-1){&lt;br /&gt;            lb.setCharAt(j,&amp;#39; &amp;#39;); // set the letter to &amp;#39; &amp;#39; to indicate it&amp;#39;s been used up&lt;br /&gt;        } else {&lt;br /&gt;            makeable=false; // j=-1 means the letter we were looking for is not there so we can&amp;#39;t make it&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;    if(makeable){&lt;br /&gt;        // we can make this word&lt;br /&gt;        if(foundwords==0){&lt;br /&gt;            stringItemSolution.setText(s); // add to the list&lt;br /&gt;        } else {&lt;br /&gt;            stringItemSolution.setText(stringItemSolution.getText()+&amp;#39;\n&amp;#39;+s); // add to the list&lt;br /&gt;        }&lt;br /&gt;        foundwords++;&lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt;dis.close(); &lt;/pre&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;br class=&quot;clear&quot; /&gt;&lt;table id=&quot;attachments&quot;&gt;
 &lt;thead&gt;&lt;tr&gt;&lt;th&gt;Attachment&lt;/th&gt;&lt;th&gt;Size&lt;/th&gt; &lt;/tr&gt;&lt;/thead&gt;
&lt;tbody&gt;
 &lt;tr class=&quot;odd&quot;&gt;&lt;td&gt;&lt;a href=&quot;http://thesamovar.net/files/countdownlettersme.jar&quot;&gt;countdownlettersme.jar&lt;/a&gt;&lt;/td&gt;&lt;td&gt;290.26 KB&lt;/td&gt; &lt;/tr&gt;
 &lt;tr class=&quot;even&quot;&gt;&lt;td&gt;&lt;a href=&quot;http://thesamovar.net/files/countdownlettersme.jad&quot;&gt;countdownlettersme.jad&lt;/a&gt;&lt;/td&gt;&lt;td&gt;398 bytes&lt;/td&gt; &lt;/tr&gt;
 &lt;tr class=&quot;odd&quot;&gt;&lt;td&gt;&lt;a href=&quot;http://thesamovar.net/files/letters.java.txt&quot;&gt;letters.java.txt&lt;/a&gt;&lt;/td&gt;&lt;td&gt;9.24 KB&lt;/td&gt; &lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
</description>
 <comments>http://thesamovar.net/countdownlettersme#comment</comments>
 <category domain="http://thesamovar.net/taxonomy/term/5">Programming</category>
 <enclosure url="http://thesamovar.net/files/countdownlettersme.jar" length="297229" type="application/java-archive" />
 <pubDate>Tue, 10 Jul 2007 02:04:32 +0100</pubDate>
 <dc:creator>thesamovar</dc:creator>
 <guid isPermaLink="false">81 at http://thesamovar.net</guid>
</item>
<item>
 <title>Programming</title>
 <link>http://thesamovar.net/programming</link>
 <description>&lt;p&gt;Not much in the way of programming related stuff at the moment. The only thing I have at the moment is my mobile phone &lt;a href=&quot;/countdownlettersme&quot;&gt;Countdown letters game solver&lt;/a&gt;, and a Python program to solve the &lt;a href=&quot;/countdownnumbers&quot;&gt;Countdown numbers game&lt;/a&gt;.&lt;br /&gt;&lt;/p&gt;&lt;p&gt;You could also see the &lt;a href=&quot;/node/9&quot;&gt;software&lt;/a&gt; I wrote for my Mathematics PhD thesis. &lt;/p&gt;&lt;br class=&quot;clear&quot; /&gt;</description>
 <comments>http://thesamovar.net/programming#comment</comments>
 <category domain="http://thesamovar.net/taxonomy/term/5">Programming</category>
 <pubDate>Tue, 10 Jul 2007 01:55:06 +0100</pubDate>
 <dc:creator>thesamovar</dc:creator>
 <guid isPermaLink="false">80 at http://thesamovar.net</guid>
</item>
<item>
 <title>Maskit</title>
 <link>http://thesamovar.net/maskit</link>
 <description>&lt;p&gt;I wrote some software to draw pictures of the Maskit slice, including pleating rays. It allows you to zoom in as far as numerical precision allows, and it has a nice graphical interface (illustrated below). If you&amp;#39;re interested in how it works, take a look &lt;a href=&quot;/node/8&quot;&gt;here&lt;/a&gt;. You can export the pictures as postscript files or into Mathematica. You can also export to binary or ASCII format, but I haven&amp;#39;t provided any documentation on these. The software runs on Windows, and requires DirectX (which should be installed on almost all versions of Windows now). If you want to try to compile and run this on Linux, let me know. It is possible, but it takes a bit of work and since each version of Linux is different I can&amp;#39;t provide a precompiled version. You can download the software &lt;a href=&quot;/files/maskit-distrib.zip&quot;&gt;here&lt;/a&gt; (360k) as a zipped folder.&lt;/p&gt;&lt;blockquote&gt;&lt;p align=&quot;left&quot;&gt;&lt;img src=&quot;/files/maskit-screenshot.jpg&quot; /&gt;&lt;/p&gt;&lt;p align=&quot;left&quot;&gt;&lt;em&gt;Maskit software screenshot &lt;/em&gt;&lt;/p&gt;&lt;/blockquote&gt;&lt;br class=&quot;clear&quot; /&gt;&lt;table id=&quot;attachments&quot;&gt;
 &lt;thead&gt;&lt;tr&gt;&lt;th&gt;Attachment&lt;/th&gt;&lt;th&gt;Size&lt;/th&gt; &lt;/tr&gt;&lt;/thead&gt;
&lt;tbody&gt;
 &lt;tr class=&quot;odd&quot;&gt;&lt;td&gt;&lt;a href=&quot;http://thesamovar.net/files/maskit-distrib.zip&quot;&gt;maskit-distrib.zip&lt;/a&gt;&lt;/td&gt;&lt;td&gt;358.92 KB&lt;/td&gt; &lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
</description>
 <comments>http://thesamovar.net/maskit#comment</comments>
 <category domain="http://thesamovar.net/taxonomy/term/1">Mathematics</category>
 <category domain="http://thesamovar.net/taxonomy/term/5">Programming</category>
 <category domain="http://thesamovar.net/taxonomy/term/10">Research</category>
 <enclosure url="http://thesamovar.net/files/maskit-distrib.zip" length="367533" type="application/x-zip-compressed" />
 <pubDate>Sun, 15 Oct 2006 04:22:43 +0100</pubDate>
 <dc:creator>thesamovar</dc:creator>
 <guid isPermaLink="false">10 at http://thesamovar.net</guid>
</item>
<item>
 <title>Programs</title>
 <link>http://thesamovar.net/node/8</link>
 <description>&lt;p&gt;As part of my &lt;a href=&quot;/thesis&quot;&gt;thesis&lt;/a&gt;, I wrote some software to draw pictures of the Maskit slice. If you only want to produce pictures of the Maskit slice, you should use the &lt;a href=&quot;/maskit&quot;&gt;graphical version&lt;/a&gt; of this software.  The Mathematica notebooks from my thesis can be downloaded &lt;a href=&quot;/files/mathematica-nodata.zip&quot;&gt;here&lt;/a&gt; (zipped folder, 40k). Some of these notebooks will work on their own (including all of the algorithms chapter notebook), but some of them require datasets produced by the C++ software. These files are approximately 120MB and too large to include on this webpage, but you can generate them yourself with the C++ software.  You can download the C++ source code only distribution &lt;a href=&quot;/files/hyperbolic-noexe.zip&quot;&gt;here&lt;/a&gt; (37k), or with Windows executable files &lt;a href=&quot;/files/hyperbolic.zip&quot;&gt;here&lt;/a&gt; (161k). I have tested the source code on MS Visual C++ and gcc/Linux. This version of the software only includes the command line version of the software. You can download the graphical version of this software, but compiling this version from the source code is quite complicated. &lt;a href=&quot;/contact&quot;&gt;Email me&lt;/a&gt; if you want to try this.&lt;/p&gt;
&lt;br class=&quot;clear&quot; /&gt;&lt;table id=&quot;attachments&quot;&gt;
 &lt;thead&gt;&lt;tr&gt;&lt;th&gt;Attachment&lt;/th&gt;&lt;th&gt;Size&lt;/th&gt; &lt;/tr&gt;&lt;/thead&gt;
&lt;tbody&gt;
 &lt;tr class=&quot;odd&quot;&gt;&lt;td&gt;&lt;a href=&quot;http://thesamovar.net/files/mathematica-nodata.zip&quot;&gt;mathematica-nodata.zip&lt;/a&gt;&lt;/td&gt;&lt;td&gt;39.61 KB&lt;/td&gt; &lt;/tr&gt;
 &lt;tr class=&quot;even&quot;&gt;&lt;td&gt;&lt;a href=&quot;http://thesamovar.net/files/hyperbolic-noexe.zip&quot;&gt;hyperbolic-noexe.zip&lt;/a&gt;&lt;/td&gt;&lt;td&gt;36.83 KB&lt;/td&gt; &lt;/tr&gt;
 &lt;tr class=&quot;odd&quot;&gt;&lt;td&gt;&lt;a href=&quot;http://thesamovar.net/files/hyperbolic.zip&quot;&gt;hyperbolic.zip&lt;/a&gt;&lt;/td&gt;&lt;td&gt;160.22 KB&lt;/td&gt; &lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
</description>
 <comments>http://thesamovar.net/node/8#comment</comments>
 <category domain="http://thesamovar.net/taxonomy/term/1">Mathematics</category>
 <category domain="http://thesamovar.net/taxonomy/term/5">Programming</category>
 <category domain="http://thesamovar.net/taxonomy/term/10">Research</category>
 <enclosure url="http://thesamovar.net/files/mathematica-nodata.zip" length="40563" type="application/x-zip-compressed" />
 <pubDate>Sun, 15 Oct 2006 04:16:49 +0100</pubDate>
 <dc:creator>thesamovar</dc:creator>
 <guid isPermaLink="false">8 at http://thesamovar.net</guid>
</item>
</channel>
</rss>
