Add tasks for all the new languages
This commit is contained in:
parent
9dc3c2bb62
commit
bba7bfd280
13208 changed files with 134745 additions and 0 deletions
25
Task/Word-wrap/LFE/word-wrap-1.lfe
Normal file
25
Task/Word-wrap/LFE/word-wrap-1.lfe
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
(defun wrap-text (text)
|
||||
(wrap-text text 78))
|
||||
|
||||
(defun wrap-text (text max-len)
|
||||
(string:join
|
||||
(make-wrapped-lines
|
||||
(string:tokens text " ") max-len)
|
||||
"\n"))
|
||||
|
||||
(defun make-wrapped-lines
|
||||
(((cons word rest) max-len)
|
||||
(let ((`#(,_ ,_ ,last-line ,lines) (assemble-lines max-len word rest)))
|
||||
(lists:reverse (cons last-line lines)))))
|
||||
|
||||
(defun assemble-lines (max-len word rest)
|
||||
(lists:foldl
|
||||
#'assemble-line/2
|
||||
`#(,max-len ,(length word) ,word ())
|
||||
rest))
|
||||
|
||||
(defun assemble-line
|
||||
((word `#(,max ,line-len ,line ,acc)) (when (> (+ (length word) line-len) max))
|
||||
`#(,max ,(length word) ,word ,(cons line acc)))
|
||||
((word `#(,max ,line-len ,line ,acc))
|
||||
`#(,max ,(+ line-len 1 (length word)) ,(++ line " " word) ,acc)))
|
||||
9
Task/Word-wrap/LFE/word-wrap-2.lfe
Normal file
9
Task/Word-wrap/LFE/word-wrap-2.lfe
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
(defun make-regex-str (max-len)
|
||||
(++ "(.{1," (integer_to_list max-len) "}|\\S{"
|
||||
(integer_to_list (+ max-len 1)) ",})(?:\\s[^\\S\\r\\n]*|\\Z)"))
|
||||
|
||||
(defun wrap-text (text max-len)
|
||||
(let ((find-patt (make-regex-str max-len))
|
||||
(replace-patt "\\1\\\n"))
|
||||
(re:replace text find-patt replace-patt
|
||||
'(global #(return list)))))
|
||||
4
Task/Word-wrap/LFE/word-wrap-3.lfe
Normal file
4
Task/Word-wrap/LFE/word-wrap-3.lfe
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
> (set test-text (++ "Even today, with proportional fonts and complex layouts, there are still cases where you need to wrap text at a specified column. "
|
||||
"The basic task is to wrap a paragraph of text in a simple way in your language. If there is a way to do this that is built-in, trivial, or "
|
||||
"provided in a standard library, show that. Otherwise implement the minimum length greedy algorithm from Wikipedia.")
|
||||
> (io:format (wrap-text text 80))
|
||||
1
Task/Word-wrap/LFE/word-wrap-4.lfe
Normal file
1
Task/Word-wrap/LFE/word-wrap-4.lfe
Normal file
|
|
@ -0,0 +1 @@
|
|||
> (io:format (wrap-text text 50))
|
||||
Loading…
Add table
Add a link
Reference in a new issue