Add tasks for all the new languages

This commit is contained in:
Tina Müller 2016-12-05 23:44:36 +01:00
parent 9dc3c2bb62
commit bba7bfd280
13208 changed files with 134745 additions and 0 deletions

View 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)))

View 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)))))

View 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))

View file

@ -0,0 +1 @@
> (io:format (wrap-text text 50))