aboutsummaryrefslogtreecommitdiff
path: root/rosetta/lines.neb
diff options
context:
space:
mode:
authormryouse2022-08-02 02:16:38 +0000
committermryouse2022-08-02 02:16:38 +0000
commitee509e05746731b12afe64bfe34284b119f6b4ae (patch)
tree3a7e2e2ea668a99ab979e5852eedb661d9723085 /rosetta/lines.neb
parent7300580eb3aacfe1b67918fb20259e3ec26559c2 (diff)
exercises
Diffstat (limited to 'rosetta/lines.neb')
-rw-r--r--rosetta/lines.neb16
1 files changed, 16 insertions, 0 deletions
diff --git a/rosetta/lines.neb b/rosetta/lines.neb
new file mode 100644
index 0000000..45a6a6f
--- /dev/null
+++ b/rosetta/lines.neb
@@ -0,0 +1,16 @@
+
+(func adjust (text width)
+ (def lines (list))
+ (def word "")
+ (for-each (split text " ")
+ (branch
+ ((eq? 0 (length word)) (redef word _item_))
+ ((<= (+ (length word) 1 (length _item_)) width)
+ (redef word (concat word " " _item_)))
+ (#true
+ (block
+ (redef lines (append lines word))
+ (redef word _item_)))))
+ (if (not (eq? 0 (length word)))
+ (append lines word)
+ lines))