Word Blender (#108)

On Wed, 10 Jan 2007 13:54:43 -0800, Phrogz wrote:

C:>ri transpose
More than one method matched your request. You can refine
your search by asking for information on one of:

 Array#transpose, Matrix#transpose

C:>ri Array.transpose
C:>ri Matrix.transpose

Thats very nice. I never realized such a great help tool exists! Thank
you
Phrogz!! :slight_smile:

On 1/10/07, James Edward G. II [email protected] wrote:

James Edward G. II

Aah, thanks so much. I must have misread that before, never noticed the
bit
about permissions. I tried changing that line before but it still didnā€™t
work since I was trying to modify the file I created with the weird
permission (whatever permission option File::CREAT would be interpreted
as).
Erasing and starting over it all works as expected, creating and
overwriting
the file on subsequent calls. Thanks!

Ruby Q. wrote:

published in various places around the web.
Bonus points for building a completely functional game!

class String
def chars
split("")
end
def sorted
chars.sort.join
end
end

Generate combinations.

def comb array, n, str = ā€œā€, &blk
0.upto(array.size - n){|i|
if 1 == n
yield str + array[i]
else
comb array[i+1ā€¦-1], n-1, str+array[i], &blk
end
}
end

word_groups = Hash.new {[]}
shorts = Hash.new {[]}
while word = gets do
next unless (word=word.downcase.delete(ā€™^a-zā€™)).size.between?(3,6)
if 6 == word.size
word_groups[word.sorted] += [ word ]
else
shorts[word.sorted] += [ word ]
end
end

word_groups.each_key{|key|
3.upto(5){|n|
combinations = []
comb( key.chars, n ){|s| combinations << s}
combinations.uniq.each{|s| word_groups[key] += shorts[s] }}}

This just solves the find-all-subwords problem:

target = ARGV[0]
dict = ARGV[1] || ā€˜sowpodsā€™

reduced = target.split(//).sort.uniq.join
primes = [2, 3, 5, 7, 11, 13]
factors = []
reduced.split(//).each_with_index {|e, i|
factors[e[0]] = primes[i]
}

target_num = 1
target.each_byte {|i| target_num *= factors[i]}

IO.foreach(dict) {|word|
word.chomp!
next unless (word =~ /^[#{reduced}]+$/) &&
(word.length < 7) && (word.length > 2)
p = 1
word.each_byte {|i| p *= factors[i]}
puts word if target_num % p == 0
}

T. W. Urp wrote:

Vincent F. wrote long time ago:

ā€œTry transposing your matrix first, if that is what you need. Are you
dealing with transformation matrices (which are not real matrices) ?ā€
Yes indeed, SVG 2D transformation matrices. These matrices are 3x3.

They never taught me about transposing, just matrix multiplication, and
googel didnt help either. What is transposing (for transformation matrices)?

Given a matrix ā€œaā€ with ā€œmā€ rows and ā€œnā€ columns

for i = 1 to m do
for j = 1 to n do
atranspose[j, i] = a[i, j]
end
end

I will look into NArray. Is NArray what you would recommend?

Yes!

ā€“
M. Edward (Ed) Borasky, FBG, AB, PTA, PGS, MS, MNLP, NST, ACMC(P)
http://borasky-research.blogspot.com/

If God had meant for carrots to be eaten cooked, He would have given
rabbits fire.

On 1/11/07, Martin DeMello [email protected] wrote:

factors[e[0]] = primes[i]
word.each_byte {|i| p *= factors[i]}
puts word if target_num % p == 0
}

Thatā€™s neat, and is a good general way of checking for inclusion (so you
can
extend it past characters in a string which might not have an .include?
method). You probably donā€™t want that .uniq in there though as that
excludes
you from matching ā€˜hellā€™ out of ā€˜helloā€™, for example.

On 1/11/07, Fedor L. [email protected] wrote:

reduced.split(//).each_with_index {|e, i|
p = 1
word.each_byte {|i| p *= factors[i]}
puts word if target_num % p == 0
}

Thatā€™s neat, and is a good general way of checking for inclusion (so you can
extend it past characters in a string which might not have an .include?
method). You probably donā€™t want that .uniq in there though as that excludes
you from matching ā€˜hellā€™ out of ā€˜helloā€™, for example.

No, I do need the uniq since I want one prime per unique letter in the
target word. I then calculate its signature by a loop over the entire
word, not the reduced word, so ā€œhellā€ is indeed matched for ā€œhelloā€
but not for, say, ā€œwhelpsā€.

martin

Iā€™d be interested in trying this, but Iā€™ve avoided dictionary-type
quizzes in the past for lack of a good dictionary file. Does anyone
have links to decent word/dictionary files? Or perhaps does Mac OS X
come with one?

On 1/5/07, Ruby Q. [email protected] wrote:

the
Bonus points for building a completely functional game!

   [1]: http://games.yahoo.com/games/texttwist.html (just one example,

java)
[2]: http://www.gamehouse.com/

Is the goal to get the most points or to get to the highest round? Do
you
get points based on the number of letters used (as in Upwords) or do you
get
points based on the obscurity of the letter to be used (as in scrabble)?

On Jan 5, 2007, at 9:53 AM, Matthew M. wrote:

Or perhaps does Mac OS X come with one?

Sure: /usr/share/dict/words

James Edward G. II

On Friday 05 January 2007 17:53, Matthew M. wrote:

Iā€™d be interested in trying this, but Iā€™ve avoided dictionary-type
quizzes in the past for lack of a good dictionary file. Does anyone
have links to decent word/dictionary files? Or perhaps does Mac OS X
come with one?

Iā€™m using the ones here: http://wordlist.sourceforge.net/
I donā€™t know how good they are, but theyā€™re ok for this particular quiz
IMHO

On 1/5/07, Jason M. [email protected] wrote:

Official scrabble list of accepted 6 letter words:
TWL-Only Six-Letter Words

My mistake, thatā€™s the list of obscure accepted 6 letter words. Iā€™ll
find a better list this afternoon.

http://www.scrabulous.com/twl_dictionary.php
Complete list of accepted scrabble words. Youā€™ll need to go through and
nuke any long wordsā€¦ I think learn Ruby in 21 days has a regex on day
8
that can assist people with this :slight_smile:

On 1/5/07, Matthew M. [email protected] wrote:

Iā€™d be interested in trying this, but Iā€™ve avoided dictionary-type
quizzes in the past for lack of a good dictionary file. Does anyone
have links to decent word/dictionary files? Or perhaps does Mac OS X
come with one?

Official scrabble list of accepted 6 letter words:
http://www.math.utoronto.ca/jjchew/scrabble/lists/ospd-only-6.html

did anyone find a unix-friendly text-twist?
the yahoo one doesnā€™t like me: ā€œNote: TextTwist is not compatible with
Unix or
Macintosh computers.ā€
and every other site with texttwist seems to use the yahoo one.

On 1/5/07, Jason M. [email protected] wrote:

Official scrabble list of accepted 6 letter words:
TWL-Only Six-Letter Words

My mistake, thatā€™s the list of obscure accepted 6 letter words. Iā€™ll
find
a better list this afternoon.

On Jan 5, 2007, at 7:53 AM, Jason M. wrote:

Is the goal to get the most points or to get to the highest round?
Do you
get points based on the number of letters used (as in Upwords) or
do you get
points based on the obscurity of the letter to be used (as in
scrabble)?

My solution doesnā€™t track ā€œpointsā€ per say, just the rounds really.
So for my code, itā€™s getting to the highest round.

Feel free to add some scoring though. I would probably score based
on words found, with bigger words earning more points.

James Edward G. II

On Sat, Jan 06, 2007, Oin M. wrote:

did anyone find a unix-friendly text-twist?
the yahoo one doesnā€™t like me: ā€œNote: TextTwist is not compatible with Unix or
Macintosh computers.ā€
and every other site with texttwist seems to use the yahoo one.

Itā€™s just a java game. Iā€™m on a mac and it works fine. If you have a
current JRE and an appropriate browser plugin, it should work.

Ben