## Monday, January 2, 2017

### 2016 Holiday Challenge: Results for Challenge 2, Candy Cane Word-Find

My readers appear to have solved this puzzle much faster than I did. Congratulations to reader Sharmin, who solved it first—a copy of Word Games 5 is on its way!

By the way, the email edition of yesterday's post was missing an embedded video, so for the benefit of my email subscribers, here's a direct link to Lisa Simpson challenging Bart Simpson to a game of rock/paper/scissors. (The video underlines that you shouldn't necessarily attribute rationality to your opponents!)

Getting back to Challenge 2, I thought people might like to see the process I use to create these word-find puzzles, so here is some detail on that.

The first thing is to rank the letters of the alphabet according to their visual density. I'll skip the steps for this and give the result:

I, Z, L, T, Y, P, C, F, J, E, S, A, B, R, G, K, H, V, X, D, U, O, Q, M, W, N

Next, we rank the words in the dictionary according to their dynamic range. Ideally, we want words like NINJA, which include both low-density letters (I, J) and high-density letters (N). That allows us to "paint" with a broad palette. But I had a hard time coming up with a holiday puzzle about ninjas, so I downloaded a list of holiday theme words from a teacher website:

Sorting these according to their dynamic range yields

Some of these looked good (like TOY) but didn't quite work out. Eventually I tried CANDY, doing an image search online for a line drawing of a candy cane. I was looking for a blocky image that would remain recognizable when converted to a low-resolution letter grid. Here was the image I chose:

I resized the image to 72 pixels by 40 pixels, and then created a histogram of pixel saturation:

Eyeballing the peaks in the histogram, I assigned a letter to each pixel according to the following rule:
• Pixel saturation 0.9 or less:  Replace pixel with C or Y (flip a coin)
• Pixel saturation between 0.9 and 2:  Replace pixel with letter A
• Pixel saturation between 2 and 3.5: Replace pixel with letter D
• Pixel saturation greater than 3.5:  Replace pixel with letter N.
Now I had a grid of letters resembling a candy cane. I ran the grid through a word-search-solver that I wrote a long time ago, just to see what words were present in the grid. I found several instances of short words like AND, with maybe a CYCAD or two—but no CANDY.

Even after ten thousand attempts, I still didn't have a grid with CANDY. I diagnosed the problem as not enough Ds next to Ys (or something like that), so I added some blurring to the pixel rule for saturation above 3.5. Instead of replacing all of these pixels with Ns, I set it to be 93% likely to replace the pixel with an N, with 7% likelihood of C, D, or Y. With this rule, the image still looked like a candy cane, and it only took around 500 attempts to produce a grid with one instance of CANDY in it. (I had to solve the puzzle myself, because my word-search solver tells me which words are in a grid, but not where they are located!)

From there I adjusted the font size and spacing of the grid in Microsoft Word, and the puzzle was finished.

Most ASCII art looks a lot nicer than this, as you can see from a google search. In part, that's because of the crudeness of my algorithm; it's also because most ASCII art uses a much larger character set with much greater dynamic range. Some programs even help themselves to different font colors.

I'll leave you with the first known example of typewriter art, this butterfly created by Flora Stacey in 1898. Stacey created striking effects by the technique of rotating her paper in the typewriter.

Nowadays you can upload images to websites like this one and have them converted into ASCII instantaneously.

Results of Challenge 3, Lewis Carroll's problem of the two walkers, coming next!