-
Notifications
You must be signed in to change notification settings - Fork 1
/
kern.rb
85 lines (69 loc) · 1.47 KB
/
kern.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
j = [
' o',
' o',
' o',
'o o',
' oo '
]
l = [
'o ',
'o ',
'o ',
'o ',
'oooo'
]
o = [
' ooo ',
'o o',
'o o',
'o o',
' ooo '
]
x = [
'o o',
' o o ',
' o ',
' o o ',
'o o'
]
y = [
'o o',
' o o ',
' o ',
' o ',
' o '
]
def concat_letters(letters)
lines = letters.first.dup
letters.drop(1).each do |letter|
memo = lines.zip(letter).map { |left_line, unpadded_right_line|
right_line = " #{unpadded_right_line}"
left = left_line.match(/ *$/)
right = right_line.match(/^ */)
left_count = left[0].size
right_count = right[0].size
# p [left_line, left_count,
# right_line, right_count, left_count + right_count]
{ left: left_line, right: right_line,
lc: left_count, rc: right_count }
}
trim_amount = memo.map { |item|
item[:lc] + item[:rc]
}.min - 1 # always leave at least 1 space
# puts '-' * 15
# puts trim_amount
# puts '-' * 15
memo.each do |item|
# left = left_line.match(/ *$/)
# right = right_line.match(/^ */)
# left_count = left[0].size
# right_count = right[0].size
left_trim_amt = [[trim_amount, item[:lc]].min, 0].max
right_trim_amt = [trim_amount - left_trim_amt, 0].max
item[:left].delete_suffix!(' ' * left_trim_amt)
item[:left] << item[:right].delete_prefix(' ' * right_trim_amt)
end
end
lines
end
puts concat_letters([l, y, y, o, x, j])