2016 Update
This commit is contained in:
parent
948b86eafa
commit
dcf5d15da3
7965 changed files with 139854 additions and 31002 deletions
55
Task/Align-columns/Aime/align-columns.aime
Normal file
55
Task/Align-columns/Aime/align-columns.aime
Normal file
|
|
@ -0,0 +1,55 @@
|
|||
data b;
|
||||
file f;
|
||||
list c, r, s;
|
||||
integer a, i, j, k, m, w;
|
||||
|
||||
b_cast(b, "Given$a$text$file$of$many$lines,$where$fields$within$a$line$\n"
|
||||
"are$delineated$by$a$single$'dollar'$character,$write$a$program\n"
|
||||
"that$aligns$each$column$of$fields$by$ensuring$that$words$in$each$\n"
|
||||
"column$are$separated$by$at$least$one$space.\n"
|
||||
"Further,$allow$for$each$word$in$a$column$to$be$either$left$\n"
|
||||
"justified,$right$justified,$or$center$justified$within$its$column.");
|
||||
|
||||
f_b_affix(f, b);
|
||||
|
||||
m = 0;
|
||||
|
||||
while (f_news(f, r, 0, 0, "$") ^ -1) {
|
||||
l_append(c, r);
|
||||
m = max(m, l_length(r));
|
||||
}
|
||||
|
||||
i = 0;
|
||||
while (i < m) {
|
||||
w = 0;
|
||||
j = 0;
|
||||
while (j < l_length(c)) {
|
||||
r = c[j];
|
||||
if (i < l_length(r)) {
|
||||
w = max(w, length(r[i]));
|
||||
}
|
||||
j += 1;
|
||||
}
|
||||
l_append(s, w + 1);
|
||||
i += 1;
|
||||
}
|
||||
|
||||
k = 3;
|
||||
while (k) {
|
||||
k -= 1;
|
||||
o_plan(l_effect("right", "center", "left")[k], " justified", "\n");
|
||||
j = 0;
|
||||
while (j < l_length(c)) {
|
||||
i = 0;
|
||||
r = c[j];
|
||||
while (i < l_length(r)) {
|
||||
w = s[i];
|
||||
m = w - length(r[i]);
|
||||
o_form("/w~3/~/w~1/", a = k * m >> 1, "", m - a, "", r[i]);
|
||||
i += 1;
|
||||
}
|
||||
o_newline();
|
||||
j += 1;
|
||||
}
|
||||
o_newline();
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue