Double Parity Vertical Redundancy Check by tabasa

d=[]\x0d
while gets\x0d
d<<$_.chomp.split('').map{|i|i.to_i}\x0d
end\x0d
v=d.map{|i|(eval i*"+")%2}\x0d
h=[]\x0d
n,m=d[0].size,d.size\x0d
n.times{|i|s=0;m.times{|j|s+=d[j][i]};h<<s%2}\x0d
a=[]\x0d
m.times{|i|t=[];n.times{|j|t<<v[i]*h[j]+d[i][j]};a<<t}\x0d
a.each{|i|puts i*""}

Note that non-ascii characters in the above source code will be escaped (such as \x9f).

download

return to the top page