-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtmux.rb
executable file
·120 lines (102 loc) · 2.12 KB
/
tmux.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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
#!/usr/bin/ruby
require 'erb'
def xy(x, y)
"\#{@x#{x}y#{y}}"
end
def full_row(i)
all_x(i).join(' ')
end
def all_x(y)
(0...9).map do |x|
xy x, y
end
end
def grid_ok
buff = []
(0...9).each do |i|
buff << is_ok(all_x(i))
buff << is_ok(all_y(i))
buff << is_ok(cell(i))
end
"\#{?\#{m:*0*,#{buff.join}},0,1}"
end
def is_ok(exprs)
all_exprs = exprs.join
(1..9).map do |i|
"\#{m:*#{i}*,#{all_exprs}}"
end.join
end
def show_state
(0...9).map do |y|
line = (0...9).map do |x|
if '25'.include? x.to_s
a = xy x, y
a + '│'
else
xy x, y
end
end.join
if '25'.include? y.to_s
' ' + line + '\n ───┼───┼───'
else
' ' + line
end
end.join('\n')
end
def all_y(x)
(0...9).map do |y|
xy x, y
end
end
def all_cell(x, y)
[0, 1, 2].map do |ax|
[0, 1, 2].map do |ay|
xy x + ax, y + ay
end
end.flatten
end
def cell(i)
all_cell (i % 3) * 3, (i / 3) * 3
end
def x_sub(var, idx)
var_len = "\#{n:#{var}}"
start_idx = "\#{e|*:2,#{idx}}"
end_idx = "\#{e|-:#{var_len},#{start_idx}}"
front_truncated = "\#{=-#{end_idx}:#{var}}"
"\#{=1:#{front_truncated}}"
end
def y_sub(var, idx)
var_len = "\#{n:#{var}}"
start_idx = "\#{e|*:2,#{idx}}"
end_idx = "\#{e|-:\#{e|-:#{var_len},#{start_idx}},1}"
front_truncated = "\#{=-#{end_idx}:#{var}}"
"\#{=1:#{front_truncated}}"
end
def more_array?(var, idx)
var_len = "\#{n:#{var}}"
i = "\#{e|*:2,#{idx}}"
"\#{e|<:#{i},#{var_len}}"
end
sud = File.read ARGV[0]
res = ''
blanks = []
lines = sud.lines
(0...9).each do |y|
row = lines[y].split('')
(0...9).each do |x|
num = row[x]
if num.nil? || num == ' ' || num == "\n"
blanks << "#{x}#{y}"
res += "set -g @x#{x}y#{y} '1'\n"
else
res += "set -g @x#{x}y#{y} '#{num}'\n"
end
end
end
res += "set -g @blanks '#{blanks.join}'\n"
File.write 'sudoku-data.conf', res
output = 'sudoku-compiled.conf'
socket = 'test-sock'
compiled = ERB.new(File.read('sudoku.conf')).result(binding)
File.write(output, compiled)
exec *(%w(tmux -L) + [socket, '-f'] + [output] + %w(attach))