From: Ionut Artarisi Date: 2007-01-08T22:06:47+09:00 Subject: Re: [QUIZ] Word Blender (#108) --nextPart17441531.fdFuUJYqkk Content-Type: multipart/mixed; boundary="Boundary-01=_XHkoFct0nb8S5KP" Content-Transfer-Encoding: 7bit Content-Disposition: inline --Boundary-01=_XHkoFct0nb8S5KP Content-Type: text/plain; charset="utf-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=C5=A3 Ar=C5=A3=C4=83ri=C5=9Fi I remembered a mistake that i had done. Well not actually a mistake. I just= =20 wrote some 10 lines of code that did some extra work that i never actually= =20 used later in the program. I deleted those lines now, which resulted in a=20 unidimensional array (it was bidimensional before). This version should be= =20 more readable and should make more sense though there's no extra=20 functionallity. So the version on rubyquiz.com should be replaced with this= =20 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=_XHkoFct0nb8S5KP Content-Type: application/x-ruby; name="texttwist-1.1.rb" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="texttwist-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 = File.open("word.lst", "r") fi = f.read.gsub("\n", " ").scan(/\w+/).to_a f.close allwords = Array.new fi.each {|word| (if ((word.length >= 3) and (word.length <= 6)) allwords << word.upcase end) } ## now they're all in an array bwords = Array.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 = 1 score = 0 star = "" while (i == 1) do puts "Pick a number between 0 and " + bwords.length.to_s + " or press Enter to end game." m = gets.chop if (m != "") n = m.to_i wordie = bwords[n].scan(/./).sort_by{rand}.to_s.upcase # word scramble puts "You have chosen the word: " + wordie foo = 0 all = allwords.dup while (foo == 0) puts "Form words! Type 0 to pick another word." guess = gets.chop.upcase o = 0 while (o < guess.length) # tests if the letters used are legal guessy = guess.dup bwords[n].scan(/./).collect{|e| (guessy = guessy.sub(e , ""))} o += 1 end if guessy == "" if (all.include? guess) # tests if the guess is in the wordlist all.delete(guess) score += guess.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 = 1337 puts " and you have " + star + " stars." end elsif (guess == "EXIT0") foo = 1337 else puts "Incorrect! Try Again!" end elsif (guess == "EXIT0") foo = 1337 else puts "The letters used were illegal. Try again." end end bwords.delete_at(n) else i = 0 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=_XHkoFct0nb8S5KP-- --nextPart17441531.fdFuUJYqkk Content-Type: application/pgp-signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.3 (GNU/Linux) iD8DBQBFokHkJRmulx2zJOARAjRhAJ48rzySMu+H1xuKBNzbgl/NcgyKpACfc0jy kTzqUtOmta1YAAoQGCGCBQQ= =jZh/ -----END PGP SIGNATURE----- --nextPart17441531.fdFuUJYqkk--