Data commit

This commit is contained in:
Ingy döt Net 2023-07-01 11:58:00 -04:00
parent 7387c8f97b
commit cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions

View file

@ -0,0 +1,16 @@
fcn format(text,how){
words:=text.split("$").apply("split").flatten();
max:=words.reduce(fcn(p,n){ n=n.len(); n>p and n or p },0);
wordsPerCol:=80/(max+1);
fmt:=(switch(how){
case(-1){ "%%-%ds ".fmt(max).fmt }
case(0) { fcn(max,w){
a:=(max-w.len())/2; b:=max-w.len() - a; String(" "*a,w," "*b);
}.fp(max)
}
case(1){ "%%%ds ".fmt(max).fmt }
});
w:=words.walker(); d:=Data(0,Int);
do{ w.pump(wordsPerCol,d,fmt).append("\n") } while(not w.atEnd);
d.text;
}

View file

@ -0,0 +1,11 @@
text:=
"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.\n";
format(text,-1).print();
format(text, 0).print();
format(text, 1).print();