From ee509e05746731b12afe64bfe34284b119f6b4ae Mon Sep 17 00:00:00 2001 From: mryouse Date: Tue, 2 Aug 2022 02:16:38 +0000 Subject: exercises --- rosetta/lines.neb | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 rosetta/lines.neb (limited to 'rosetta/lines.neb') 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)) -- cgit v1.2.3