Box Relatives

Thoughts about puzzles, math, coding, and miscellaneous

April 28, 2013
by Alex
0 comments

Code first, optimize later (but don’t forget to optimize!)

I am totally on board with the “code first, optimize later” 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’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.

If you haven’t done Matt Gaffney’s “Shake It Up” crossword you might want to do it before reading further, because there will be massive spoilers. Done? All right, let’s continue.
Continue Reading →

CROSSWORD RACE!

April 10, 2013 by Alex | 2 Comments

Here we are trying something new.

Every week for a few weeks I’ll be participating in a crossword race against one of the greatest crossword solvers of all time. But since I’d never have a chance in a fair fight, he’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.

Huge thanks to Brendan Emmett Quigley for allowing us to use his puzzles and to Mike Richards for allowing us to use the awesome XWord software for these videos.

Once I get a blog up on Crossword Nexus you will be able to find these videos there. Enjoy!

April 7, 2013
by Alex
1 Comment

XKCD’d

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 daughter asked “What makes wind?” 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.

She paused for about five seconds and then asked “So why does hot air rise?”

March 20, 2013
by Alex
0 comments

On infinity

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. 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.

I only know how to divide numbers. Infinity, truth, beauty — those are not numbers.

Then the person says, No, I mean, what is:
inftyAnd I say, Oh.  Um, 3.

— John Derbyshire, in “Prime Obsession” (addendum by Alex Boisvert)

February 24, 2013
by Alex
6 Comments

Two related problems (and their solutions)

Consider two problems you’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? Well, I’ll tell you how — by the good old GCD. Here’s my method for solving these problems:
Continue Reading →

November 20, 2012
by Alex
3 Comments

Wikipedia Regex Search Updated

The news first: I’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 the most recent Matt Gaffney Contest using the search, but it didn’t turn anything up. Why? Because “Oracle of Omaha” isn’t a full-fledged Wikipedia page, just a redirect, and I exclude redirects from my results.

So what’s the fix here? The obvious fix is to include redirects in my results, but I can’t just include all of them wholesale. Just look at all the pages that redirect to “Condoleezza Rice” to see why. No thanks.

So is there a way to be more judicious about choosing which redirects to use? There must be; after all, Onelook seems to handle it just fine. I’m thinking for now to compare each redirect to a list of known “good” results, maybe from my clue database or the collaborative word list. 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 — I’ll have to add it.)

Is there another way to determine which redirects to use? I’d love to hear suggestions. Anything I can do to improve my tool would be great.

November 17, 2012
by Alex
5 Comments

Crossword Butler

So the Crossword Butler domain expires in a month, and I’m not sure if I should re-up. It hasn’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 — 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’s a good idea to have a central repository for all those things, but it hasn’t worked out quite yet.

If I do keep it around, there are a few things I need to do:

  • Make an HTML5 solver so that users could access Crossword Butler from their mobile devices. I’ve contacted some people about that but nothing has panned out.
  • 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’t have that safety valve where if there’s not enough support for a puzzle, the constructor doesn’t have to launch. I need to figure out how I can work with Kickstarter to do that.
  • Advertise more, maybe? Boy, this certainly isn’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’ve had nothing since.

Even if I do these things, there’s no guarantee this will work. But at least I’d stand a chance of surviving. I don’t know. Thoughts?

November 5, 2012
by Alex
0 comments

Joon’s puzzler

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 toolkit for Python so I thought I’d test it out on this problem. Here’s what I came up with:

#!/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

To use it you will need a fairly comprehensive list of phrases — the data dump from Wiktionary is what I used here. Just run it as

puzzler.py enwiki.txt 3 4

and it will spit out:

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

(Yes, WordNet thinks that “big” and “bad” are synonyms.)

You may notice that Joon’s intended answer isn’t among the results — one of those phrases wasn’t on Wiktionary … until I added it (it will probably be in the next data dump).

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 “light switch” and “short-change”. “Well liquors” and “good spirits” is a good one too. Anything else? Feel free to experiment with the code and let me know in the comments.

September 7, 2012
by Alex
0 comments

Anagram Word Ladders

The most recent NPR puzzle was an anagram word ladder, and I thought I’d try my hand at finding a solution in Perl*. Well, I did it and I’d like to share the code with anyone who’s interested. You can find it here.

* Remember how I was going to be leaving Perl a while back? Yeah, that never happened.

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 all 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’t post them here. But just as an example, here it is turning NINETY to EIGHTH (an old puzzle from Merl Reagle):

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

*Boy, does the Scrabble dictionary have some terrible words in it. Yecch.

I don’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!

September 4, 2012
by Alex
0 comments

Agatha Christie

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’ve never heard of, but in Agatha Christie you’ve met the murderer and understood the motive by the end of the first act. However … I just saw a Miss Marple mystery on Netflix in which … well, I think it’s best explained by a short one-act play which shows how I imagine the co-conspirators came up with their plan.

[SPOILER ALERT]

Continue Reading →