-
Notifications
You must be signed in to change notification settings - Fork 0
/
scratch.rb
51 lines (39 loc) · 824 Bytes
/
scratch.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
=begin
#.##..##.
..#.##.#.
##......#
##......#
..#.##.#.
..##..##.
#.#.##.#.
one line mismatch
one spot mismatch
"====="
"..##..##."
"====="
"####..##."
"====="
"#..#..##."
"====="
=end
def find_horizontal_mirror_with_smudge(pattern)
mirror = {}
pattern = pattern.map(&:join)
(1..pattern.size-1).each do |index|
top_half = pattern[0..index-1]
bottom_half = pattern[index..-1]
n_elem = [top_half.size, bottom_half.size].min
top_half.reverse!
mismatch_index = (0..n_elem-1).select do |i|
top_half[i] != bottom_half[i]
end
if mismatch_index.size == 1
indx = mismatch_index[0]
top, bottom = top_half[indx], bottom_half[indx]
(top.chars.each_index.select do |index|
top[index] != bottom[index]
end)
p "===="
end
end
end