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
|
{
sub("^ ", "[.] ");
gsub(" ", " [.]");
}
/^\[/ {
for (i = 1; i <= NF; i++) {
x = substr($i, 2, 1);
if (x == ".") continue;
a[i] = a[i] x;
b[i] = b[i] x;
}
}
/^move/ {
count = $2;
from = $4;
to = $6;
for (i = 1; i <= count; i++) {
x = substr(a[from], 1, 1);
a[from] = substr(a[from], 2);
a[to] = x a[to];
}
x = substr(b[from], 1, count);
b[from] = substr(b[from], count+1);
b[to] = x b[to];
}
END {
for (i = 1; a[i]; i++) {
printf substr(a[i], 1, 1);
}
printf "\n";
for (i = 1; b[i]; i++) {
printf substr(b[i], 1, 1);
}
printf "\n";
}
|