June 2018 Update

This commit is contained in:
Ingy döt Net 2018-06-22 20:57:24 +00:00
parent ba8067c3b7
commit 22f33d4004
5278 changed files with 84726 additions and 14379 deletions

View file

@ -1,55 +1,45 @@
data b;
file f;
text n, t;
list c, r, s;
integer a, i, j, k, m, w;
integer a, i, 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.");
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);
f.b_affix(b);
m = 0;
while (f_news(f, r, 0, 0, "$") ^ -1) {
l_append(c, r);
m = max(m, l_length(r));
while (f.news(r, 0, 0, "$") ^ -1) {
c.append(r);
m = max(m, ~r);
}
i = 0;
while (i < m) {
w = 0;
j = 0;
while (j < l_length(c)) {
r = c[j];
if (i < l_length(r)) {
for (, r in c) {
if (i < ~r) {
w = max(w, length(r[i]));
}
j += 1;
}
l_append(s, w + 1);
s.append(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;
for (k, t in list("left", "center", "right")) {
o_(t, " justified\n");
for (, r in c) {
for (i, n in r) {
m = s[i] - ~n;
o_form("/w~3/~/w~1/", a = (2 - k) * m >> 1, "", m - a, "", n);
}
o_newline();
j += 1;
}
o_newline();
}