Just another update
This commit is contained in:
parent
a25938f123
commit
00a190b0a6
6591 changed files with 94363 additions and 23227 deletions
27
Task/Word-wrap/Mathematica/word-wrap-1.math
Normal file
27
Task/Word-wrap/Mathematica/word-wrap-1.math
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
string="In olden times when wishing still helped one, there lived a king whose daughters were all beautiful, but the youngest was so beautiful that the sun itself, which has seen so much, was astonished whenever it shone in her face. Close by the king's castle lay a great dark forest, and under an old lime-tree in the forest was a well, and when the day was very warm, the king's child went out into the forest and sat down by the side of the cool fountain, and when she was bored she took a golden ball, and threw it up on high and caught it, and this ball was her favorite plaything.";
|
||||
wordWrap[textWidth_,spaceWidth_,string_]:=Module[{start,spaceLeft,masterString},
|
||||
spaceLeft=textWidth;
|
||||
start=1;
|
||||
masterString={};
|
||||
Do[
|
||||
If[i+1>Length@StringSplit@string
|
||||
,
|
||||
p=StringSplit[string][[start;;i]];
|
||||
AppendTo[masterString,{StringJoin@@Riffle[p,StringJoin@ConstantArray[" ",spaceWidth]]}]
|
||||
,
|
||||
If[StringLength[StringSplit@string][[i+1]]+spaceWidth>spaceLeft
|
||||
,
|
||||
spaceLeft=textWidth-StringLength[StringSplit@string][[i]];
|
||||
start=i;
|
||||
AppendTo[masterString,{StringJoin@@Riffle[p,StringJoin@ConstantArray[" ",spaceWidth]]}]
|
||||
,
|
||||
spaceLeft-=StringLength[StringSplit@string][[i]];
|
||||
spaceLeft-=spaceWidth;
|
||||
p=StringSplit[string][[start;;i]]
|
||||
]
|
||||
]
|
||||
,
|
||||
{i,1,Length@StringSplit@string}
|
||||
];
|
||||
StringJoin@@Riffle[masterString,"\n"]
|
||||
];
|
||||
2
Task/Word-wrap/Mathematica/word-wrap-2.math
Normal file
2
Task/Word-wrap/Mathematica/word-wrap-2.math
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
wordWrap[72, 1, string]
|
||||
wordWrap[80, 1, string]
|
||||
Loading…
Add table
Add a link
Reference in a new issue