--nextPart17441531.fdFuUJYqkk Content-Type: multipart/mixed; boundaryoundary-01 HkoFct0nb8S5KP" Content-Transfer-Encoding: 7bit Content-Disposition: inline --Boundary-01 HkoFct0nb8S5KP Content-Type: text/plain; charset tf-8" Content-Transfer-Encoding: quoted-printable Content-Disposition: inline On Sunday 07 January 2007 15:04, Ionut Artarisi wrote: > This is my first ruby program that actually does all it's supposed to do. > It doesn't have a lot of style, but hopefully my next programs will look > better. The wordlist is from wordlist.sourceforge.net and the first part of > the program reads the word.lst file and puts all the words in an array. > > Hope it does what it's supposed to do, as i couldn't see the texttwist on > yahoo. > I'm also attaching the Unnoficial Jargon File Wordlist word.lst file. > > -Ionuţ Arţrii I remembered a mistake that i had done. Well not actually a mistake. I just wrote some 10 lines of code that did some extra work that i never actually used later in the program. I deleted those lines now, which resulted in a unidimensional array (it was bidimensional before). This version should be more readable and should make more sense though there's no extra functionallity. So the version on rubyquiz.com should be replaced with this one, for the sake of future readers if it's not too much of a trouble. Thank you. And thank you for rubyquiz.com. It's fantastic! --Boundary-01 HkoFct0nb8S5KP Content-Type: application/x-ruby; name exttwist-1.1.rb" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename exttwist-1.1.rb" ### getting words from the list in word.lst # assuming that each word in the file is on a different line # and using the Unofficial Jargon File Word Lists from http://wordlist.sourceforge.net # f ile.open("word.lst", "r") fi .read.gsub("\n", " ").scan(/\w+/).to_a f.close allwords rray.new fi.each {|word| (if ((word.length > ) and (word.length < )) allwords << word.upcase end) } ## now they're all in an array bwords rray.new allwords.each {|word| (if (word.scan(/./).length 6) bwords << word end) } bwords.collect{|c| c.upcase!} # code above sorts words with 6 letters into bwords i score star " while (i 1) do puts "Pick a number between 0 and " + bwords.length.to_s + " or press Enter to end game." m ets.chop if (m ! ") n .to_i wordie words[n].scan(/./).sort_by{rand}.to_s.upcase # word scramble puts "You have chosen the word: " + wordie foo all llwords.dup while (foo 0) puts "Form words! Type 0 to pick another word." guess ets.chop.upcase o while (o < guess.length) # tests if the letters used are legal guessy uess.dup bwords[n].scan(/./).collect{|e| (guessy uessy.sub(e , ""))} o + end if guessy "" if (all.include? guess) # tests if the guess is in the wordlist all.delete(guess) score + uess.length puts "Your score is now: " + score.to_s if (guess bwords[n]) #tests and rewards if the guess is the original word star << "*" foo 337 puts " and you have " + star + " stars." end elsif (guess "EXIT0") foo 337 else puts "Incorrect! Try Again!" end elsif (guess "EXIT0") foo 337 else puts "The letters used were illegal. Try again." end end bwords.delete_at(n) else i puts "Your final score was: " + score.to_s + " and you have gathered " + star + " stars. (One star for each original 6 letter word found.)" end end --Boundary-01 HkoFct0nb8S5KP-- --nextPart17441531.fdFuUJYqkk Content-Type: application/pgp-signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.3 (GNU/Linux) iD8DBQBFokHkJRmulx2zJOARAjRhAJ48rzySMu+H1xuKBNzbgl/NcgyKpACfc0jy kTzqUtOmta1YAAoQGCGCBQQ h/ -----END PGP SIGNATURE----- --nextPart17441531.fdFuUJYqkk--