Worlds you can create with Hex

While walking to Uni this morning Edd and me though about how many words you could spell with only using Hex chars {a..f}. I was thinking about this all day so I sat down and wrote a little program that would solve this problem for me:
First we have to generate all possible char combination:
From http://ribalba.de/geek/proj/hexword/wordcreate.py
 1: #!/usr/bin/python
2:
3: #We want to create all possible combinations out of these chars
4: # a b c d e f ' '
5: #Somehow '' is not handeld correct so we have to remove it later
6: wl = ['a','b', 'c', 'd', 'e', 'f', ' ']
7: out = []
8:
9: def recLoop(txt):
10: if len(txt) >= len(wl):
11: #Add to list and remove space
12: out.append(txt.replace(' ',''))
13: else:
14: for i in set(wl):
15: recLoop(txt + i)
16:
17: #Start the recursion
18: recLoop("")
19:
20: #So we remove duplicates
21: outset = set(out)
22:
23: #And print
24: for w in set (outset):
25: print w

The output file can be found here : http://ribalba.de/geek/proj/hexword/outfile this file has 335923 lines and is 2.5M big. So now we have to find out how many words are actually 'real' English words. To make it easy I just used aspell and some perl.
Source can be found here: http://ribalba.de/geek/proj/hexword/findwords
 1: #!/usr/bin/perl
2:
3: use Text::Aspell;
4:
5: my $speller = Text::Aspell->new;
6:
7: die unless $speller;
8:
9: # Set some options
10: $speller->set_option('sug-mode','fast');
11: $speller->set_option('clean-words','true');
12: $speller->set_option('ignore-case','true');
13:
14: open FILE, "outfile" or die $!;
15: while (my $line = <FILE>) {
16: chomp $line;
17: # check a word
18: if( $speller->check($line)) {
19: print $line . "\n";
20: }
21:
22: }

And this outputs us a nice list of all the words you can spell in English with the Hex chars, see here: http://ribalba.de/geek/proj/hexword/hexwords
There are some freaky words there.
--------------------
CAFEBABE :)

1 comment:

Matt said...

CAFEBABE indeed ;)