Previous blog: November 16, 2009 – DRAFT: SCRABBLE SERIES

I had a free blog hosted by cjb.net from January 2006 to May 2011. My blog at cjb.net was mysteriously deleted in early December 2008. Here’s a post from my previous blog.

 

scrabble
Looks like I’ve started a Scrabble series.

Here we have an example simple program to convert words into their Scrabble score. It could have been written far more efficiently and elegantly but I’ve written it awfully simply so that you see the basic structure. It’s written in python which I believe is very similar to Javascript but it’s likely that this program could be implemented in almost any programming language.

I’ve written it for the English Scrabble letter values so you will need to change the values for different conversions. This short program will also accept phrases although of course phrases are no good for Scrabble. If for some reason you wanted to convert a whole page of text into Scrabble scores I suggest that you expand it to give you a Scrabble score for words and phrases – maybe chop the input up on punctuation, etc.

As the program stands it simply ignores values that are not specified. Different languages will of course have different entries. I hope that it demonstrates how simple it is to achieve simple things with basic programming skills.

Since Scrabble is good for learning and expanding the vocabulary, I expect to be bringing you some example words in the style of Sesame Street. I think that I may start with the word harbinger although that would only be any good in Scrabble if somebody had already used the word ‘arb’. [Edit: ‘harbi’ and ‘harbin’ may be words acceptable under Scrabble rules. There you go, learning already.] I’m not really sure that that’s acceptable under Scrabble rules (have to look it up) and of course somebody else could add an ‘s’ and get a good score.

#!/usr/bin/python
import sys

letters = {
	'a' : 1,	'A' : 1,
	'b' : 3,	'B' : 3,
	'c' : 3,	'C' : 3,
	'd' : 2,	'D' : 2,
	'e' : 1,	'E' : 1,
	'f' : 4,	'F' : 4,
	'g' : 2,	'G' : 2,
	'h' : 4,	'H' : 4,
	'i' : 1,	'I' : 1,
	'j' : 8,	'J' : 8,
	'k' : 5,	'K' : 5,
	'l' : 1,	'L' : 1,
	'm' : 3,	'M' : 3,
	'n' : 1,	'N' : 1,
	'o' : 1,	'O' : 1,
	'p' : 3,	'P' : 3,
	'q' : 10,	'Q' : 10,
	'r' : 1,	'R' : 1,
	's' : 1,	'S' : 1,
	't' : 1,	'T' : 1,
	'u' : 1,	'U' : 1,
	'v' : 4,	'V' : 4,
	'w' : 4,	'W' : 4,
	'x' : 8,	'X' : 8,
	'y' : 4,	'Y' : 4,
	'z' : 10,	'Z' : 10
	}

while 1:
    word = sys.stdin.readline()
        val = 0
	for i in word:
	    if i in letters:
	        val = val + letters[i]
	    else:	
		pass
    print "value is ", val

 

This entry was posted in previous blog and tagged , . Bookmark the permalink.

Leave a Reply

Your email address will not be published.