Word Scramble

Word Scramble

wordScramble.rb

As I mentioned in "#29 Sudoku Solver" on Sudoku Solver, word scramble is a classic game. There is something fascinating about a game that can hold your attention while exercising your vocabulary. This classic game can be found in newspapers, magazines, and even books dedicated solely to word scrambles. But who needs those when you can customize your own game?

The Code

 unless ARGV[0] and File.exists?(ARGV[0])
     puts "\n\nUsage is wordScramble.rb <word.file>\n\n"
     exit
 end

 tries = 10

 words = File.readlines(ARGV[0])
 mystery_word = words[rand(words.size)].chomp

 scramble_word = mystery_word.split(//).sort_by{rand}.join ...

Get Wicked Cool Ruby Scripts now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.