@@ -11,8 +11,6 @@ def is_symmetry_line?(lines, (a, b))
11
11
end
12
12
13
13
def find_symmetry ( lines )
14
- puts "find_symmetry for:"
15
- puts lines
16
14
idx_pairs = [ ]
17
15
lines . each_with_index . each_cons ( 2 ) do |( ( line_a , idx_a ) , ( line_b , idx_b ) ) |
18
16
idx_pairs << [ idx_a , idx_b ] if line_a == line_b
@@ -36,33 +34,23 @@ def summarize(pattern)
36
34
find_symmetry ( lines . map ( &:chars ) . transpose . map ( &:join ) ) [ 0 ]
37
35
end
38
36
39
- puts "original: #{ original } "
40
37
counts = Set [ original ]
41
38
42
39
( 0 ...lines . length ) . each do |y |
43
40
( 0 ...lines [ 0 ] . length ) . each do |x |
44
- puts "Swapping at #{ y } /#{ x } , counts is #{ counts } "
45
41
new_lines = lines . map ( &:clone )
46
- new_lines [ y ] [ x ] = new_lines [ y ] [ x ] == "#" ? "." : "#"
42
+ new_lines [ y ] [ x ] = ( new_lines [ y ] [ x ] == "#" ) ? "." : "#"
47
43
48
44
count_new = find_symmetry ( new_lines )
49
- if count_new
50
- puts "found #{ count_new } "
51
- count_new . each { |c | counts . add ( 100 * c ) }
52
- end
45
+ count_new &.each { |c | counts . add ( 100 * c ) }
53
46
54
47
count_new = find_symmetry ( new_lines . map ( &:chars ) . transpose . map ( &:join ) )
55
- if count_new
56
- puts "found #{ count_new } "
57
- count_new . each { |c | counts . add ( c ) }
58
- end
48
+ count_new &.each { |c | counts . add ( c ) }
59
49
end
60
50
61
51
break if counts . size == 2
62
52
end
63
53
64
- puts "original: #{ original } "
65
- p counts
66
54
counts . to_a . find { |c | c != original }
67
55
end
68
56
0 commit comments