Tuesday, October 25, 2005
Tuesday, October 25, 2005 6:48:16 AM (India Standard Time, UTC+05:30) ( Technology )
How do you get a kid to be interested in learning to program?   Show them how to create a program to do/help do their homework:
 
Josh has frequent assignments that involve reading a page long story and then answering some questions about the story.  Included are some scrambled words that appeared in the story.  Josh asked if a computer (like what they used in "National Treasure" to decode Abby's password) could help out.
 
The result, I told Josh that he could use any program he created to do his homework, and that I would help him out with his programs.
 
To show him how easy it could be, I created a program to provide a list of possible matches to word scramble questions.
 
create procedure usp_TextUnscramble @input varchar(20)
as
declare @query varchar(1000),
 @position int, @length int, @currentLetter char(1)
 
set @query = 'select top 1000 WordItem from WordList where '
set @length = LEN(@input)
set @position = 1
print @length
 
while @position <= @length
BEGIN
 set @currentLetter =  SUBSTRING(@input, @position, 1) 
 set @query = @query + ' charindex('''
 set @query = @query + @currentLetter
 set @query = @query + ''''
 set @query = @query + ', WordItem) > 0 AND '
 
 set @position = @position + 1
END
set @query = @query + ' LEN(WordItem) = ' + convert(varchar(5), @length)
 
print @query
exec (@query)
go
 
exec usp_TextUnscramble 'rmragrporm'
 
The WordList table is an import of the Moby Word List.  Tonight we are going to wrap this code in a Windows application so that he doesn't need to use Query Analyzer to run it.
Comments are closed.