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

<channel>
	<title>Box Relatives</title>
	<atom:link href="http://alexboisvert.com/musings/feed/" rel="self" type="application/rss+xml" />
	<link>http://alexboisvert.com/musings</link>
	<description>Thoughts about puzzles, math, coding, and miscellaneous</description>
	<lastBuildDate>Sun, 28 Apr 2013 04:11:48 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.5.1</generator>
		<item>
		<title>Code first, optimize later (but don&#8217;t forget to optimize!)</title>
		<link>http://alexboisvert.com/musings/2013/04/28/code-first-optimize-later-but-dont-forget-to-optimize/</link>
		<comments>http://alexboisvert.com/musings/2013/04/28/code-first-optimize-later-but-dont-forget-to-optimize/#comments</comments>
		<pubDate>Sun, 28 Apr 2013 04:07:29 +0000</pubDate>
		<dc:creator>Alex</dc:creator>
				<category><![CDATA[coding]]></category>
		<category><![CDATA[puzzles]]></category>

		<guid isPermaLink="false">http://alexboisvert.com/musings/?p=278</guid>
		<description><![CDATA[I am totally on board with the &#8220;code first, optimize later&#8221; school of programming. But sometimes one can forget to optimize, which can be a minor issue (if the code was already pretty optimized) or a major one (if there&#8217;s &#8230; <a href="http://alexboisvert.com/musings/2013/04/28/code-first-optimize-later-but-dont-forget-to-optimize/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>I am totally on board with the &#8220;code first, optimize later&#8221; school of programming.  But sometimes one can forget to optimize, which can be a minor issue (if the code was already pretty optimized) or a major one (if there&#8217;s a glaringly obvious improvement to be made).  I recently coded something up to help someone out and it definitely needed some optimization before it was done.</p>
<p>If you haven&#8217;t done <a href="http://xwordcontest.com/2013/04/mgwcc-255-friday-april-19th-2013-shake-it-up.html">Matt Gaffney&#8217;s &#8220;Shake It Up&#8221; crossword</a> you might want to do it before reading further, because there will be massive spoilers.  Done?  All right, let&#8217;s continue.<br />
<span id="more-278"></span></p>
<p>So Matt asked me if there would be a way to fill a corner of a crossword grid with a 4&#215;4 block of letters such that (a) one square was a Qu rebus and (b) the 4&#215;4 block contained a 17-letter word following Boggle rules.  In Boggle, you try to make long words by moving like a king in chess through the 4&#215;4 block, never landing on the same letter more then once.  Now, it&#8217;s certainly easy to make a block like that which spells, say, SESQUICENTENNIALS:</p>
<pre>
SESQ
NECI
TENN
SLAI
</pre>
<p>but it&#8217;s harder to make one that would then fit inside a crossword.  Here, for instance, we have the troubling EEEL and SNTS, letter patterns which don&#8217;t fit in many good crossword entries.</p>
<p>My first thought was: for each 17-letter Boggle word (I started with INCONSEQUENTIALLY, SESQUICENTENNIALS and QUADRICENTENNIALS, but others are possible) I created a random grid with those letters, and then checked to see if the word was actually inside with Boggle rules, and then if the resulting letter patterns were good for a crossword.  I was pretty happy with this solution, but it was painfully slow!  Why?  Well, essentially because 16! is a humongous number (20,922,789,888,000 &#8212; approximately the number of red blood cells in the human body, thanks <a href="http://www.wolframalpha.com/input/?i=16!">Wolfram Alpha!</a>) and so I was making 20 trillion grids (give or take) for each word I wanted to analyze.  I had a working solution, but it was unbearably slow, so I needed to optimize.</p>
<p>My next thought was: instead of making a random grid and checking if it&#8217;s Boggle-friendly, why not just start with a Boggle-friendly grid?  This turned out to be no harder to code up than checking to see if a grid contained the word and it dropped the number of possible grids from 20 trillion to under 400,000.  Still a big number, but WAY smaller.  (For reference: 20 trillion seconds is over 600,000 years; 400,000 seconds is about four and a half days).  This made the algorithm quite fast.</p>
<p><a href="http://pastebin.com/HVpQWpWz">You can check out the code here</a>.  I wrote it in C++ because that&#8217;s how I write all my code when I need it to run fast.  You&#8217;ll note in the code that there&#8217;s another optimization that can be made, but at this point I&#8217;m happy with how fast it ran.  Oh, and it did work for Matt &#8212; he was able to take some of the output and make a pretty nice crossword with it.</p>
<p>Enjoy!</p>
]]></content:encoded>
			<wfw:commentRss>http://alexboisvert.com/musings/2013/04/28/code-first-optimize-later-but-dont-forget-to-optimize/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>CROSSWORD RACE!</title>
		<link>http://alexboisvert.com/musings/2013/04/10/crossword-race/</link>
		<comments>http://alexboisvert.com/musings/2013/04/10/crossword-race/#comments</comments>
		<pubDate>Wed, 10 Apr 2013 06:10:59 +0000</pubDate>
		<dc:creator>Alex</dc:creator>
				<category><![CDATA[puzzles]]></category>

		<guid isPermaLink="false">http://alexboisvert.com/musings/?p=271</guid>
		<description><![CDATA[Here we are trying something new. Every week for a few weeks I&#8217;ll be participating in a crossword race against one of the greatest crossword solvers of all time. But since I&#8217;d never have a chance in a fair fight, &#8230; <a href="http://alexboisvert.com/musings/2013/04/10/crossword-race/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>Here we are trying something new.</p>
<p><iframe width="560" height="315" src="http://www.youtube.com/embed/3kz5z7mobBM" frameborder="0" allowfullscreen></iframe></p>
<p>Every week for a few weeks I&#8217;ll be participating in a crossword race against one of the greatest crossword solvers of all time.  But since I&#8217;d never have a chance in a fair fight, he&#8217;s going to get an increasingly ludicrous handicap each time out.  In this first episode,  he has to enter all the entries in the grid backward.  Will that be enough for me to win?  THE SUSPENSE IS KILLING ME.</p>
<p>Huge thanks to <a href="http://www.brendanemmettquigley.com">Brendan Emmett Quigley</a> for allowing us to use his puzzles and to Mike Richards for allowing us to use <a href="http://sourceforge.net/projects/wx-xword/">the awesome XWord software</a> for these videos.</p>
<p>Once I get a blog up on Crossword Nexus you will be able to find these videos there.  Enjoy!</p>
]]></content:encoded>
			<wfw:commentRss>http://alexboisvert.com/musings/2013/04/10/crossword-race/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>XKCD&#8217;d</title>
		<link>http://alexboisvert.com/musings/2013/04/07/xkcdd/</link>
		<comments>http://alexboisvert.com/musings/2013/04/07/xkcdd/#comments</comments>
		<pubDate>Sun, 07 Apr 2013 05:58:34 +0000</pubDate>
		<dc:creator>Alex</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://alexboisvert.com/musings/?p=268</guid>
		<description><![CDATA[Dammit, this exact thing happened to me today, but with a different question. My family and I were driving from Palm Springs back to Los Angeles through the San Gorgonio Pass, one of the windiest places in the country. My &#8230; <a href="http://alexboisvert.com/musings/2013/04/07/xkcdd/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p><a href="http://xkcd.com/1145/"><img src="http://imgs.xkcd.com/comics/sky_color.png" /></a></p>
<p>Dammit, this exact thing happened to me today, but with a different question.  My family and I were driving from Palm Springs back to Los Angeles through the <a href="http://en.wikipedia.org/wiki/San_Gorgonio_Pass">San Gorgonio Pass</a>, one of the windiest places in the country.  My daughter asked &#8220;What makes wind?&#8221; and I told her that since hot air rises, this creates a vacuum for cold air to rush into.  Since the air in the desert is consistently hotter than that near the ocean, there is a near-constant wind rushing through the pass to get from the ocean to the desert.</p>
<p>She paused for about five seconds and then asked &#8220;So why does hot air rise?&#8221;</p>
]]></content:encoded>
			<wfw:commentRss>http://alexboisvert.com/musings/2013/04/07/xkcdd/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>On infinity</title>
		<link>http://alexboisvert.com/musings/2013/03/20/on-infinity/</link>
		<comments>http://alexboisvert.com/musings/2013/03/20/on-infinity/#comments</comments>
		<pubDate>Wed, 20 Mar 2013 00:47:27 +0000</pubDate>
		<dc:creator>Alex</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://alexboisvert.com/musings/?p=261</guid>
		<description><![CDATA[Nonmathematical people sometimes ask me, You know math, huh? Tell me something I’ve always wondered, What is infinity divided by infinity? I can only reply, The words you just uttered do not make sense. That was not a mathematical sentence. &#8230; <a href="http://alexboisvert.com/musings/2013/03/20/on-infinity/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<blockquote><p>Nonmathematical people sometimes ask me, You know math, huh? Tell me something I’ve always wondered, What is infinity divided by infinity?</p>
<p>I can only reply, The words you just uttered do not make sense. That was not a mathematical sentence. You spoke of infinity as if it were a number. It’s not. You may as well ask, What is truth divided by beauty? I have no clue.</p>
<p>I only know how to divide numbers. Infinity, truth, beauty &#8212; those are not numbers.</p>
<p>Then the person says, No, I mean, what is:<br />
<a href="http://alexboisvert.com/musings/wp-content/uploads/2013/03/infty.png"><img class="aligncenter size-full wp-image-262" alt="infty" src="http://alexboisvert.com/musings/wp-content/uploads/2013/03/infty.png" width="243" height="109" /></a>And I say, Oh.  Um, 3.</p></blockquote>
<p>&#8211; John Derbyshire, in &#8220;Prime Obsession&#8221; (addendum by Alex Boisvert)</p>
]]></content:encoded>
			<wfw:commentRss>http://alexboisvert.com/musings/2013/03/20/on-infinity/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Two related problems (and their solutions)</title>
		<link>http://alexboisvert.com/musings/2013/02/24/two-related-problems-and-their-solutions/</link>
		<comments>http://alexboisvert.com/musings/2013/02/24/two-related-problems-and-their-solutions/#comments</comments>
		<pubDate>Sun, 24 Feb 2013 00:41:43 +0000</pubDate>
		<dc:creator>Alex</dc:creator>
				<category><![CDATA[math]]></category>
		<category><![CDATA[puzzles]]></category>

		<guid isPermaLink="false">http://alexboisvert.com/musings/?p=253</guid>
		<description><![CDATA[Consider two problems you&#8217;ve probably heard before: Given a five-gallon bucket and a three-gallon bucket, measure exactly four gallons of water. Given a five-minute hourglass and a three-minute hourglass, measure exactly seven minutes. These problems are clearly related, but how? &#8230; <a href="http://alexboisvert.com/musings/2013/02/24/two-related-problems-and-their-solutions/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>Consider two problems you&#8217;ve probably heard before:</p>
<ul>
<li>Given a five-gallon bucket and a three-gallon bucket, measure exactly four gallons of water.</li>
<li>Given a five-minute hourglass and a three-minute hourglass, measure exactly seven minutes.</li>
</ul>
<p>These problems are clearly related, but how?  Well, I&#8217;ll tell you how &#8212; by the good old GCD.  Here&#8217;s my method for solving these problems:<br />
<span id="more-253"></span></p>
<ul>
<li>Let N and M be the two numbers for the measures you have (3 and 5 in the above problems).  Let A be the amount you want to measure.</li>
<li>Find d = gcd(N,M).  If A is not a multiple of d, the problem is impossible.  In our cases, we have d = 1, so we&#8217;re good.</li>
<li>Find integers a, b (possibly negative) such that A = aN + bM.  This is always possible, as A is a multiple of d.  Usually it can be solved by inspection, but you can always go for the <a href="http://en.wikipedia.org/wiki/Euclidean_algorithm">Euclidean algorithm</a> if you&#8217;re stuck.  For example, we have 3 * 3 &#8211; 1 * 5 = 4 (also 2 * 5 &#8211; 2 * 3) and 2 * 5 &#8211; 1 * 3 = 7.</li>
<li>Use the linear combination to solve the problem!  (Wait, what?)</li>
</ul>
<p>The last step is the hardest to understand.  Let&#8217;s start with the buckets.  We interpret a positive bucket as filling a bucket with water, and a negative bucket as pouring one out.  So if we use the linear combination 3 * 3 &#8211; 1 * 5 = 4, we will have to fill 3 three-gallon buckets with water, and pour out 1 five-gallon bucket.  Specifically:</p>
<ol>
<li>Fill the three-gallon bucket and pour it into the five-gallon bucket. ( 1 * 3)</li>
<li>Fill the three-gallon bucket again, and pour enough of it into the five-gallon bucket until the five-gallon is full (2 * 3).</li>
<li>Pour out the five-gallon bucket. (2 * 3 &#8211; 1 * 5)</li>
<li>Fill up the three-gallon bucket.  Now you&#8217;ve got four gallons! (3 * 3 &#8211; 1 * 5).</li>
</ol>
<p>That&#8217;s fairly easy to understand, because it&#8217;s easy to interpret a &#8220;negative bucket&#8221; as pouring out water.  For the hourglass problem we have to figure out how to measure &#8220;negative time.&#8221;</p>
<p>We&#8217;ve got a five-minute hourglass and a three-minute hourglass.  We can subtract them to make two minutes: turn them both over at the same time.  When the three-minute one is done, there will be two left in the five-minute one.  If we then flip over the three-minute timer and wait until the five-minute one finishes, flip over the three-minute one to get two additional minutes.  See what we did there?  We measured the difference between the three-minute timer and the five-minute timer inside the three-minute timer.</p>
<p>How does this apply to our problem? We&#8217;ve got 2 * 5 &#8211; 1 * 3 = 7.  Let&#8217;s separate that as 1 * 5 + ( 1 * 5 &#8211; 1 * 3) and interpret this as &#8220;Start the five-minute timer and three-minute timer at the same time.  Take the difference in the three-minute timer and add it on at the end.&#8221;  Easy-peasy!</p>
<p>Challenge questions (all apply to both hourglasses and buckets):</p>
<ul>
<li>Given a four-minute hourglass and a seven-minute hourglass, measure nine minutes.</li>
<li>Given a three-minute hourglass and a seven-minute hourglass, measure nine minutes.</li>
<li>Given a two-minute hourglass and a seven-minute hourglass, measure nine minutes.</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://alexboisvert.com/musings/2013/02/24/two-related-problems-and-their-solutions/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Wikipedia Regex Search Updated</title>
		<link>http://alexboisvert.com/musings/2012/11/20/wikipedia-regex-search-updated/</link>
		<comments>http://alexboisvert.com/musings/2012/11/20/wikipedia-regex-search-updated/#comments</comments>
		<pubDate>Tue, 20 Nov 2012 17:48:50 +0000</pubDate>
		<dc:creator>Alex</dc:creator>
				<category><![CDATA[coding]]></category>

		<guid isPermaLink="false">http://alexboisvert.com/musings/?p=250</guid>
		<description><![CDATA[The news first: I&#8217;ve updated the Wikipedia Regex Search to include Wiktionary in its results. The Wikipedia results have also been updated to be current as of November 1st. Now the problem: to test it out, I attempted to solve &#8230; <a href="http://alexboisvert.com/musings/2012/11/20/wikipedia-regex-search-updated/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>The news first: I&#8217;ve updated the <a href="http://crosswordnexus.com/wiki.php">Wikipedia Regex Search</a> to include Wiktionary in its results.  The Wikipedia results have also been updated to be current as of November 1st.</p>
<p>Now the problem: to test it out, I attempted to solve the most recent <a href="http://www.crosswordfiend.com/blog/2012/11/20/mgwcc-233/">Matt Gaffney Contest</a> using the search, but it <a href="http://crosswordnexus.com/wiki.php?regex=o*+of+o*&#038;searchtype=regular&#038;searchin=Both&#038;first=0&#038;atleast=any&#038;atmost=any">didn&#8217;t turn anything up</a>.  Why?  Because &#8220;Oracle of Omaha&#8221; isn&#8217;t a full-fledged Wikipedia page, just a redirect, and I exclude redirects from my results.</p>
<p>So what&#8217;s the fix here?  The obvious fix is to include redirects in my results, but I can&#8217;t just include all of them wholesale.  Just look at all <a href="http://toolserver.org/~dispenser/cgi-bin/rdcheck.py?page=Condoleezza_Rice">the pages that redirect to &#8220;Condoleezza Rice&#8221;</a> to see why.  No thanks.</p>
<p>So is there a way to be more judicious about choosing which redirects to use?  There must be; after all, <a href="http://www.onelook.com/?w=oracle+of+o*&#038;ls=a&#038;loc=2osdf">Onelook seems to handle it just fine</a>.  I&#8217;m thinking for now to compare each redirect to a list of known &#8220;good&#8221; results, maybe from my clue database or <a href="http://alexboisvert.com/xwordlist">the collaborative word list</a>.  If a redirect page appears in one of those, then maybe I could include it and just give it the same score as the page it redirects to.  (Incidentally, it is in my clue database, but not the collaborative word list &#8212; I&#8217;ll have to add it.)</p>
<p>Is there another way to determine which redirects to use?  I&#8217;d love to hear suggestions.  Anything I can do to improve my tool would be great.</p>
]]></content:encoded>
			<wfw:commentRss>http://alexboisvert.com/musings/2012/11/20/wikipedia-regex-search-updated/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Crossword Butler</title>
		<link>http://alexboisvert.com/musings/2012/11/17/crossword-butler-2/</link>
		<comments>http://alexboisvert.com/musings/2012/11/17/crossword-butler-2/#comments</comments>
		<pubDate>Sat, 17 Nov 2012 04:23:01 +0000</pubDate>
		<dc:creator>Alex</dc:creator>
				<category><![CDATA[puzzles]]></category>

		<guid isPermaLink="false">http://alexboisvert.com/musings/?p=248</guid>
		<description><![CDATA[So the Crossword Butler domain expires in a month, and I&#8217;m not sure if I should re-up. It hasn&#8217;t really been used the way I thought it might. The idea was that puzzlemakers would just make the puzzles and I &#8230; <a href="http://alexboisvert.com/musings/2012/11/17/crossword-butler-2/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>So the <a href="http://crosswordbutler.com">Crossword Butler</a> domain expires in a month, and I&#8217;m not sure if I should re-up.  It hasn&#8217;t really been used the way I thought it might.  The idea was that puzzlemakers would just make the puzzles and I would handle all the hard parts &#8212; distribution, collecting payment, managing usernames and password, etc.  Turns out that most puzzlemakers who have gone the independent route recently have opted to handle all that themselves.  I still think it&#8217;s a good idea to have a central repository for all those things, but it hasn&#8217;t worked out quite yet.</p>
<p>If I do keep it around, there are a few things I need to do:</p>
<ul>
<li>Make an HTML5 solver so that users could access Crossword Butler from their mobile devices.  I&#8217;ve contacted some people about that but nothing has panned out.</li>
<li>Get integration with Kickstarter.  Independent puzzlemakers want to know that they will have a base of support before launching.  Crossword Butler as currently built doesn&#8217;t have that safety valve where if there&#8217;s not enough support for a puzzle, the constructor doesn&#8217;t have to launch.  I need to figure out how I can work with Kickstarter to do that.</li>
<li>Advertise more, maybe?  Boy, this certainly isn&#8217;t my strong point (despite the fact that I actually do work in the marketing industry).  I thought I had some potential clients lined up at first, but they fell through, and I&#8217;ve had nothing since.</li>
</ul>
<p>Even if I do these things, there&#8217;s no guarantee this will work.  But at least I&#8217;d stand a chance of surviving.  I don&#8217;t know.  Thoughts?</p>
]]></content:encoded>
			<wfw:commentRss>http://alexboisvert.com/musings/2012/11/17/crossword-butler-2/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Joon&#8217;s puzzler</title>
		<link>http://alexboisvert.com/musings/2012/11/05/joons-puzzler/</link>
		<comments>http://alexboisvert.com/musings/2012/11/05/joons-puzzler/#comments</comments>
		<pubDate>Mon, 05 Nov 2012 03:49:06 +0000</pubDate>
		<dc:creator>Alex</dc:creator>
				<category><![CDATA[coding]]></category>
		<category><![CDATA[puzzles]]></category>

		<guid isPermaLink="false">http://alexboisvert.com/musings/?p=244</guid>
		<description><![CDATA[Joon recently posted the following on Twitter: wordplay #puzzler: think of two unrelated phrases, both with enumeration 3, 4. the 3-letter words are synonyms; so are the 4-letter words. Well, I had just recently downloaded the unbelievably awesome natural language &#8230; <a href="http://alexboisvert.com/musings/2012/11/05/joons-puzzler/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>Joon recently posted <a href="https://twitter.com/joonpahk/status/264028534496976896">the following on Twitter</a>:</p>
<blockquote><p>wordplay #puzzler: think of two unrelated phrases, both with enumeration 3, 4. the 3-letter words are synonyms; so are the 4-letter words. </p></blockquote>
<p>Well, I had just recently downloaded the unbelievably awesome <a href="http://nltk.org/">natural language toolkit for Python</a> so I thought I&#8217;d test it out on this problem.  Here&#8217;s what I came up with:</p>
<pre>
#!/usr/bin/python

from nltk.corpus import wordnet as wn
import re
import sys

myfile = sys.argv[1]
word1_length = int(sys.argv[2])
word2_length = int(sys.argv[3])

def get_synonyms(word, length):
    '''
    Gets all synonyms of `word` of length `length`
    '''
    syns = list()
    synsets = wn.synsets(word)
    for synset in synsets:
        for w in synset.lemma_names:
            if len(w) == length and w != word and w not in syns:
                syns.append(w)
    return syns

fid = open(myfile,'r')
dict = [x.rstrip('\r\n') for x in fid.readlines()]
fid.close()

# Slim this down a bit
my_pattern = r'^[a-z]{%i}_[a-z]{%i}$' % (word1_length, word2_length)
my_phrases = [x for x in dict if re.match(my_pattern,x)]

# Go through and check
for p in my_phrases:
    w1 = p[:word1_length]
    w2 = p[word1_length+1:]
    # Get synonyms of the appropriate length
    l1 = get_synonyms(w1,word1_length)
    l2 = get_synonyms(w2,word2_length)
    if len(l1) != 0 and len(l2) != 0:
        for t1 in l1:
            for t2 in l2:
                test_phrase = t1 + '_' + t2
                if test_phrase in my_phrases:
                    print p + ' -> ' +  test_phrase
</pre>
<p>To use it you will need a fairly comprehensive list of phrases &#8212; the <a href="http://dumps.wikimedia.org/enwiktionary/latest/">data dump from Wiktionary</a> is what I used here.  Just run it as</p>
<pre>
puzzler.py enwiki.txt 3 4
</pre>
<p>and it will spit out:</p>
<pre>
bad_lots -> big_deal
bad_lots -> big_band
bad_mind -> big_head
big_head -> bad_mind
bum_rush -> rat_race
had_best -> get_well
hit_home -> off_base
off_base -> hit_home
rat_race -> bum_rush
</pre>
<p>(Yes, <a href="http://wordnetweb.princeton.edu/perl/webwn?s=big&#038;sub=Search+WordNet&#038;o2=&#038;o0=1&#038;o8=1&#038;o1=1&#038;o7=&#038;o5=&#038;o9=&#038;o6=&#038;o3=&#038;o4=&#038;h=">WordNet thinks that &#8220;big&#8221; and &#8220;bad&#8221; are synonyms</a>.)</p>
<p>You may notice that <a href="https://twitter.com/joonpahk/status/264436934020046848">Joon&#8217;s intended answer</a> isn&#8217;t among the results &#8212; one of those phrases wasn&#8217;t on Wiktionary &#8230; until I added it (it will probably be in the next data dump).</p>
<p>Anyway!  You may notice that the code offers you room to work with other word lengths.  Is there anything interesting good there?  Well, I kind of like &#8220;light switch&#8221; and &#8220;short-change&#8221;.  &#8220;Well liquors&#8221; and &#8220;good spirits&#8221; is a good one too.  Anything else?  Feel free to experiment with the code and let me know in the comments.</p>
]]></content:encoded>
			<wfw:commentRss>http://alexboisvert.com/musings/2012/11/05/joons-puzzler/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Anagram Word Ladders</title>
		<link>http://alexboisvert.com/musings/2012/09/07/anagram-word-ladders/</link>
		<comments>http://alexboisvert.com/musings/2012/09/07/anagram-word-ladders/#comments</comments>
		<pubDate>Fri, 07 Sep 2012 00:47:43 +0000</pubDate>
		<dc:creator>Alex</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://alexboisvert.com/musings/?p=238</guid>
		<description><![CDATA[The most recent NPR puzzle was an anagram word ladder, and I thought I&#8217;d try my hand at finding a solution in Perl*. Well, I did it and I&#8217;d like to share the code with anyone who&#8217;s interested. You can &#8230; <a href="http://alexboisvert.com/musings/2012/09/07/anagram-word-ladders/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p><a href="http://www.npr.org/2012/09/02/160444345/an-amusing-set-of-19th-century-riddles">The most recent NPR puzzle was an anagram word ladder</a>, and I thought I&#8217;d try my hand at finding a solution in Perl*.  Well, I did it and I&#8217;d like to share the code with anyone who&#8217;s interested.  <a href="http://pastebin.com/ySVPSvLj">You can find it here.</a></p>
<p><em>* Remember how I was <a href="http://alexboisvert.com/musings/2011/05/19/deprecated-perl/">going to be leaving Perl</a> a while back? Yeah, that never happened.</em></p>
<p>As far as I know, this is the first coded-up solution to anagram word ladders publicly available.  It relies on a breadth-first search, which has a few advantages: (1) it is guaranteed to find a solution if one exists, and (2) it will actually find <strong>all</strong> of the shortest solutions, up to anagrams of intermediate words.  There were tons of short solutions to the AUTUMN-LEAVES puzzle from NPR, and I won&#8217;t post them here.  But just as an example, here it is turning NINETY to EIGHTH (an old puzzle from Merl Reagle):</p>
<pre>
NINETY WITNEY* WHITEY EIGHTY EIGHTH
NINETY INTONE TOEING HOGTIE EIGHTH
NINETY WITNEY TEWING* WEIGHT EIGHTH
NINETY WITNEY WHITEY WEIGHT EIGHTH
NINETY WITNEY WHITEY EIGHTY EIGHTH
NINETY TYNING NIGHTY EIGHTY EIGHTH
NINETY NITERY* HINTER HITHER EIGHTH
NINETY NITERY HINTER HITHER EIGHTH
NINETY WITNEY WHITEN WEIGHT EIGHTH
NINETY INTONE ETHION HOGTIE EIGHTH
NINETY SENNIT THEINS EIGHTS EIGHTH
NINETY INTERN HINTER HITHER EIGHTH
NINETY TYNING* NIGHTY EIGHTY EIGHTH
NINETY WITNEY WHITEN WEIGHT EIGHTH
NINETY SENNIT INGEST EIGHTS EIGHTH
</pre>
<p><em>*Boy, does the Scrabble dictionary have some terrible words in it. Yecch.</em></p>
<p>I don&#8217;t know if anyone will find this code useful in any way, but there it is.  And man, if someone wants to write it in C/C++ so it could run faster, that would be excellent.  Anyway, enjoy!</p>
]]></content:encoded>
			<wfw:commentRss>http://alexboisvert.com/musings/2012/09/07/anagram-word-ladders/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Agatha Christie</title>
		<link>http://alexboisvert.com/musings/2012/09/04/agatha-christie/</link>
		<comments>http://alexboisvert.com/musings/2012/09/04/agatha-christie/#comments</comments>
		<pubDate>Tue, 04 Sep 2012 02:30:56 +0000</pubDate>
		<dc:creator>Alex</dc:creator>
				<category><![CDATA[miscellaneous]]></category>

		<guid isPermaLink="false">http://alexboisvert.com/musings/?p=235</guid>
		<description><![CDATA[I like Agatha Christie novels a lot, and one reason is that the end is often deducible. In Sherlock Holmes stories, they usually pull something out at the end that you&#8217;ve never heard of, but in Agatha Christie you&#8217;ve met &#8230; <a href="http://alexboisvert.com/musings/2012/09/04/agatha-christie/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>I like Agatha Christie novels a lot, and one reason is that the end is often deducible.  In Sherlock Holmes stories, they usually pull something out at the end that you&#8217;ve never heard of, but in Agatha Christie you&#8217;ve met the murderer and understood the motive by the end of the first act.  However &#8230; I just saw a Miss Marple mystery on Netflix in which &#8230; well, I think it&#8217;s best explained by a short one-act play which shows how I imagine the co-conspirators came up with their plan.</p>
<p>[SPOILER ALERT]</p>
<p><span id="more-235"></span></p>
<p>A: Hey, I think we should kill my cousin for the inheritance money and I&#8217;ve got a great way to do it.</p>
<p>B: Great!  What did you have in mind?</p>
<p>A: All right, here&#8217;s what we do.  First, we find a girl scout that kinda looks like my cousin.  We tell her we&#8217;re film executives and ask her to come by the hotel the night we&#8217;ll murder my cousin.  We bring her in, do her hair, put her in my cousin&#8217;s dress, and drug her.  Next, you drive her to that playboy&#8217;s house, strangle her there and leave the body.</p>
<p>B: Wait, I thought we were killing your cousin?</p>
<p>A: I&#8217;m getting there.  See, all this time, my cousin has been dancing in plain view of everyone on the ballroom floor.  When you get back from the playboy&#8217;s house, we drug her too and tell her to go to my room.  She&#8217;ll fall asleep, at which point we kill her.  We can be playing bridge in front of everyone for almost this whole time, which can be our alibi.  The next day, we&#8217;ll dress my cousin in the girl scout&#8217;s clothes, steal someone&#8217;s car, drive her to the abandoned quarry and light the car on fire.  See, everyone will think the girl scout is my cousin and vice versa!</p>
<p>B: Doesn&#8217;t the playboy know your cousin?  Won&#8217;t he know it&#8217;s not her?</p>
<p>A: Oh, he&#8217;s a drunk.  I&#8217;ll go identify the body at the morgue and the police probably won&#8217;t let anyone else see the body, right?</p>
<p>B: Um, okay.  So, that&#8217;s one plan.  But also &#8212; hear me out &#8212; since we&#8217;re going to drug your cousin anyway, why don&#8217;t we just put cyanide in her drink instead of sleeping pills?  She will drop dead on the dance floor and no one will be able to trace it back to us.</p>
<p>A:</p>
<p>B:</p>
<p>A: That&#8217;s stupid.</p>
<p>B: You&#8217;re right, that&#8217;s stupid.  Don&#8217;t know what I was thinking.</p>
<p>A: Shall we go find a girl scout, then?</p>
<p>B: I&#8217;ll drive.</p>
]]></content:encoded>
			<wfw:commentRss>http://alexboisvert.com/musings/2012/09/04/agatha-christie/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

<!-- Dynamic page generated in 0.762 seconds. -->
<!-- Cached page generated by WP-Super-Cache on 2013-06-18 21:44:25 -->
