IntegreMatrix

Hello All,
I have put together some code (using a book as a guide!!) to create an
integer matrix as follows:

class IntegerMatrix

def initialize(rows,cols)
@rows, @cols = rows, cols
@data = (0…rows).map{(0…cols).map{0}}
end

attr_reader :rows, :cols

def dimensions
[self.rows,self.cols]
end

def get(rowidx, colidx)
@data[rowidx][colidx]
end
alias [] get

def put(rowidx,colidx,value)
raise TypeError “non integer value in IntegerMatrix” unless
value.is_a? Integer
@data[rowidx][colidx]=value
end
alias []= put
end

def to_s
(0…self.rows).map{|r|
(0…self.cols).map{|c| “%5d”%self[r,c]}.join(" “)
}.join(”\n")
end

testm = IntegerMatrix.new(2,3)
testm[0,0]=68; testm[0,1]=94; testm[0,2]=-2
testm[1,0]=11; testm[1,1]=7; testm[1,2]=50

puts testm

and produces my test matrix as follows:

68 94 -2
11 7 50

my problem is how do i take it to the next level so that it will read a
.csz file and populate the matrix with its contents?.. is there a
straight forward way to do this?.. or does anyone know any good
websites/resources that can help with this.

Cheers!

  • John

#####################################################################################
This e-mail message has been scanned for Viruses and Content and cleared
by MailMarshal
#####################################################################################