STEPHEN BECKER I V
9/28/2004 2:14:00 PM
Should rindex work for an array of arrays? I am starting the playfair
cypher, you get a key and append the alphabet to it then remove dups
and change J to I, then make that in to a matrix .
mat[0].rindex("b") works right
but not
mat.rindex("b")
Do i need a string match type of thing?
####code
def removedup(a) # i want to change a to an array then use uniq
b=('a'..'z').to_a
a<<b.to_s
a.gsub!("j","i")
a.gsub!(/\s/, '')
loc=0
while loc<a.size
for i in loc+1 .. a.size
a[i]='' if a[loc]==a[i]
end
loc+=1
end
return a
end
def makematrix(a)
count = 0
mx = Array.new(5)
for i in 0 .. (5 - 1)
row = Array.new(5, 0)
for j in 0 .. (5 - 1)
row[j] = a[count].chr #make a matrix of the letters in a
count += 1
end
mx[i] = row
end
return mx
end
print "Enter a key: "
a=gets.downcase
print removedup(a)
tmat=makematrix(a)
print tmat.rindex("x") # will this work?
####code