Wednesday, May 18, 2011

Lets' Ruby!

Here is my first Ruby Code purposely to convert any information system to soft set format, very easy and simple huh!






class Softset
attr_accessor :item, :rekod

def initialize(item, rekod)
@item = item
@rekod = rekod
end
end

dataset=[]
f= File.new(ARGV[0], "r")
linecounter=1;
while !f.eof?
line=f.gets
line = line.split(/\s+/)
(line.length).times do |i|
dataset.push(Softset.new(i.to_s+line[i],linecounter))
end
linecounter += 1
end


ss = Hash.new
dataset.each do |a|
ss[a.item] ||= []
ss[a.item]<< a.rekod
end

p ss





ohh Sorry! Terspeaking London pulak!

dan ini input dan outputnya

2 comments:

Pasang Pelayar

 1. Kalau ikut kamus dewan, istilah install diertikankepada pasang, iaitu memasang perkakasan dan perisian ke dalam komputer. jadi dalam kes...