問題はこちらのリンクから。
http://qiita.com/Nabetani/items/6a9f5593d0f3d7e0568c
def count_line(bd)
ct = [0]*6
lines = []
5.times{|y|
w = Array.new(5,false)
6.times{|x|
w[x] = true unless bd[y][x] == bd[y+1][x]
}
lines << w
}
lines.each{|row|
c = 0
row.each{|cell|
if cell
c += 1
else
if c > 0
ct[c-1] += 1
c = 0
end
end
}
ct[c-1] += 1 if c > 0
}
ct
end
def solve(q)
bd = q.scan(/../).map{|e| e.to_i(8)}.map{|e| ("%06b"%e).split('')}
h_line_count = count_line(bd)
v_line_count = count_line(bd.transpose)
h_line_count.zip(v_line_count).map{|c1,c2| c1 + c2}.join(',')
end
DATA.readlines.each do |line|
no,q,a,d = line.chop.split(/\s+/)
ans = solve(q)
print no + "\t" + ans
puts ans == a ? ' o' : ' x'
end
__END__
0 060276724276 6,2,1,1,0,1
1 770175454177 2,3,0,3,1,0
2 743733377170 9,3,1,0,0,0
3 724212121273 5,2,1,1,1,1