Skip to content

Instantly share code, notes, and snippets.

@mizuhara
Created December 8, 2013 05:45
Show Gist options
  • Save mizuhara/7853779 to your computer and use it in GitHub Desktop.
Save mizuhara/7853779 to your computer and use it in GitHub Desktop.
def count_lines(board)
borders = []
board.each do |e|
a = [false] * 5
a.size.times do |i|
a[i] = true if e[i] != e[i + 1]
end
borders << a
end
borders = borders.transpose
lines = [0] * 6
borders.each do |border|
count = 0
border.size.times do |i|
if border[i]
count += 1
elsif !count.zero?
lines[count - 1] += 1
count = 0
end
end
lines[count - 1] += 1 unless count.zero?
end
lines
end
def solve(src)
board = src.scan(/[0-9]{2}/).map { |e| sprintf("%03b", e[0]) + sprintf("%03b", e[1]) }
vertical_lines = count_lines(board)
board = board.map { |e| e.split('') }.transpose.map { |e| e.join('') }
horizontal_lines = count_lines(board)
vertical_lines.zip(horizontal_lines).map { |e1, e2| e1 + e2 }.join(',')
end
DATA.readlines.each do |line|
no, src, expected = line.chop.split(/\s+/)
actual = solve(src)
puts actual == expected ? '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
4 100000000000 3,0,0,0,0,0
5 000002000000 4,0,0,0,0,0
6 003622223600 0,4,0,4,0,0
7 520073737070 8,3,1,1,0,0
8 770077007700 0,0,0,0,0,5
9 555555555514 2,0,0,0,2,2
10 764252427600 4,0,4,0,2,0
11 774555554177 3,3,1,3,0,0
12 674574754557 11,5,0,1,0,0
13 000000000000 0,0,0,0,0,0
14 777777777777 0,0,0,0,0,0
15 774377777577 6,0,2,0,0,0
16 070777777777 0,1,1,0,0,0
17 373737373737 0,0,0,0,0,1
18 603260327725 30,0,0,0,0,0
19 466331144663 30,0,0,0,0,0
20 000000000242 3,2,0,0,0,0
21 567656043772 18,2,1,0,0,0
22 200763012420 15,4,1,0,0,0
23 400101140052 14,3,0,0,0,0
24 764767476476 13,2,0,1,0,0
25 001110140110 12,2,1,0,0,0
26 765405076527 16,3,0,1,0,0
27 377323370373 8,4,2,0,0,0
28 250541131216 11,5,2,0,0,0
29 744165741476 12,3,2,0,0,0
30 042101000300 10,3,0,0,0,0
31 002004554101 11,3,1,0,0,0
32 371707762706 15,1,1,0,0,0
33 130371310175 7,3,1,2,0,0
34 212537003613 13,2,1,1,1,0
35 157700063411 15,3,0,0,0,1
36 011500036007 6,7,1,0,0,0
37 743113313517 17,2,1,0,0,0
38 174105270405 13,3,1,1,0,0
39 427272200311 13,3,2,0,0,0
40 725370332237 12,5,1,1,0,0
41 005640420046 12,1,3,0,0,0
42 700350001101 14,3,1,0,0,0
43 577627744076 16,1,1,1,0,0
44 620332232007 10,4,2,1,0,0
45 260406401000 15,1,1,0,0,0
46 737272723276 5,0,0,0,3,0
47 000400040444 7,0,2,0,0,0
48 370222002177 13,2,2,0,0,0
49 372236024656 9,3,2,0,1,0
50 276131137003 11,6,2,0,0,0
51 742134007240 13,4,2,0,0,0
52 777721775571 13,1,2,0,0,0
53 700301232233 11,2,3,0,0,0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment