Monday, November 12, 2012

Dirty Letterpress

My friend Andy introduced me to an iphone game called letterpress. The concept is pretty simple and the game is easy to learn - you have a board full of letters and you can create words out of any number of them. You get points for ever letter used, subject to some nuances about how they are defended and such.
iPhone Screenshot 1
(The picture is from the appstore link above)

Andy beat me a couple of times quite handily. Which got me thinking about how this was a rather simple string search problem that I was failing at. Enter python.

#!/usr/bin/python
import sys

board = sorted(sys.argv[1].lower())

d = open('/usr/share/dict/words')
for w in d:
s = sorted(w.strip().lower())
if len(s) < 9: continue
i = 0; j = 0
while i < len(s) and j < len(board):
if s[i] == board[j]:
i = i+1
j = j+1
elif s[i] > board[j]:
j = j+1
else:
j = len(board)
if i == len(s):
print len(s), " ", w.strip()


And the expected results:

letterpress > ./letterpress.py evkrvtzahfcyxvgatiwigoezy | sort -nr
12   vociferative
12   overactivity
12   excogitative
11   viaggiatory
11   theatricize
11   rhyotaxitic
11   overagitate
11   heterotaxic
11   heterotaxia
11   gravitative
11   fevertwitch
11   exhortative
10   whitterick
10   vociferize
10   vociferate
10   victoriate
10   verificate
10   twitchfire
10   thieftaker

Needless to say Andy caught on quite quick that something was amiss :) I resigned.





Wednesday, October 31, 2012

[books] Hydrogen Sonata

The Hydrogen Sonata (Culture, #10)The Hydrogen Sonata by Iain M. Banks
My rating: 4 of 5 stars

Ian M. Bank's latest work is another Culture novel, with all the elements that make culture novels fun - androids, avatars, knife missles, Minds, GSVs. Includes the introduction of another pan-galactic species or two and contrasts between AI-life and bio-life. Its a fun read overall, though not the best Culture novel ever. If you're a Banks fan or a Culture fan, you should definitely read it. If you've never read Ian M Banks before, I would suggest Player of Games or Surface Detail before this one.

View all my reviews

Tuesday, August 21, 2012

[books] Blood Song


Blood Song (Raven's Shadow, #1)Blood Song by Anthony  Ryan
My rating: 5 of 5 stars

Every now and then, you stumble across an author through blind luck (or Amazon's recommendation algorithms) and discover a real gem. This book is one of those.

Blood Song is a great mix of politics, action, mystery, magic - all the elements of an epic fantasy novel. It tracks the life of a warrior from childhood through training into battle. Its ending is semi-conclusive, certainly paving the road for book 2, which I look forward to. Ryan's writing is really great, considering that the book is self published via amazon. Apparently it had a bunch of grammatical and other errors, but they have since been fixed.

At a $2.99 price point, I cannot recommend this book enough. I enjoyed it far more than Wizard's First Rule or A Game of Thrones - the story is very compelling and it has fewer downright nasty or gory bits. The only downside of the book is the lack of history about the world that he builds - the politicking is explained somewhat but nowhere close to the detail that Martin or Tolkien would go into.


View all my reviews

Sunday, July 15, 2012

[books] The Blacksmith's Son


The Blacksmith's Son (Mageborn #1)The Blacksmith's Son by Michael G. Manning
My rating: 4 of 5 stars

The Blacksmith's Son is Michael Manning's first book and it as a really great read. It has some of the traditional elements of fantasy (wizards, mages, runes, spells, hero who doesn't know his power, love interest etc), but the Manning manages to make the story interesting and does a great job with the writing.

The general idea probably feels familiar to anyone who has read sufficient number of fantasy books - hero whose parents were killed when he was a baby, raised in relative poverty, discovers his powers post puberty, love interest, chief antagonist etc. What makes the story and the book interesting is the relatively fresh writing style - Manning inserts enough quirky humor in there and makes the characters seem more 'normal' and less dour than say Tolkien's. Don't expect the deep lore of Tolkien, but its far, far better than say Wizard's First Rule which I hated.

Fun, quick read, I look forward to the next one in the series.


View all my reviews

Thursday, June 21, 2012

Mapping Caps Lock to Control on Windows 7

I find the Caps Lock key completely useless. On all my computers, I map it to the control key. This is rather straightforward to do on a Mac and in Linux, but slightly harder on a Windows 7 machine. Just slightly.

There are a few different tricks that exist on the web, but the easiest I found was the registry hack - all you need to do is create a new REG_BINARY key in HKLM/System/Control/Keyboard Layout (note the singular) called Scancode Map , put in the value below, and restart your machine.

Here is the MSDN article on the Scan Code Mapper. Basically, you can instruct it to remap keys to do whatever you wish. Two common configurations:


1. Map Caps Lock to Control (this is what I use) -  
00000000 00000000 02000000 1D003A00 00000000


2. Swap Caps and Control (I have no idea why someone would want to do this)
00000000 00000000 03000000 3A001D00 1D003A00 00000000

Obviously, use this at your own risk (though I think the risk of something going dramatically wrong is very minor). For the nerds, read the aforelinked MSDN article - the numbers actually make sense.

Saturday, May 12, 2012

[books] Reamde

ReamdeReamde by Neal Stephenson
My rating: 3 of 5 stars

Better than Anathem worse than Snow Crash. Fast read and a lot of fun. Much more like Snow Crash than any other recent Stephenson book - almost like his comeback novel. This is a fast paced adventure through a bunch of countries - mixing in computers, security, terrorisms, guns and what have you. I have always loved Stephenson's detail - his computer environments, his knowledge of how computer security actually works - all quite legitimate. This adds a sense of believability to his books that I really enjoy. If you like vintage Stephenson (ie not the Baroque Cycle stuff), you'll like this.

View all my reviews

[books] Ready Player One

Ready Player OneReady Player One by Ernest Cline
My rating: 4 of 5 stars

Fast, fun, awesome read. If you like Neal Stephenson, you'll like Cline. Immaculately researched, really readable, great combination of real and virtual worlds. Somewhat predictable, language is rather straightforward (unlike, say, Feersum Endjinn), but overall a wholly enjoyable read. Recommended.

View all my reviews