Skip to content

Instantly share code, notes, and snippets.

@AnimaWish
Created February 23, 2013 01:29
Show Gist options
  • Select an option

  • Save AnimaWish/5017873 to your computer and use it in GitHub Desktop.

Select an option

Save AnimaWish/5017873 to your computer and use it in GitHub Desktop.
example = [ ['a', 'b', 'c', 'd', 'e'],
['f', 'g', 'h', 'i', 'j'],
['k', 'l', 'm', 'n', 'o'],
['p', 'q', 'r', 's', 't'],
['u', 'v', 'w', 'x', 'y']]
$letterhash = Hash.new
('a'..'z').each do |letter|
row = 0
locarray = Array.new
example.each do |x|
location = [row, x.index(letter)]
unless location.include? nil
locarray << location
end
row += 1
end
$letterhash[letter] = locarray
print letter; print $letterhash[letter]; puts
end
def findfriends(wordsearch, ain)
foundcharacter = wordsearch[ain[0]][ain[1]]
puts foundcharacter
friends = Array.new
[ain[0]-1, ain[0], ain[0]+1].map do |x|
[ain[1]-1, ain[1], ain[1]+1].map do |y|
friends << [x,y]
end
end
friends.each do |x|
print $letterhash.key([x])
end
end
findfriends(example, [2,2])
puts
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment