fork download
  1. (defun pad (string new-length)
  2. (concatenate 'string
  3. string
  4. (if (< (length string) new-length)
  5. (make-string (- new-length (length string))
  6. :initial-element #\Space)
  7. nil)))
  8.  
  9. (defun transpose-text (string-list)
  10. (let* ((max-length (reduce #'max (mapcar #'length string-list)))
  11. (padded-list (mapcar (lambda (x) (pad x max-length)) string-list))
  12. (max-y (length padded-list))
  13. (max-x (length (nth 0 padded-list))))
  14. (mapcar (lambda (x) (string-right-trim " " x))
  15. (loop for y below max-x collect
  16. (concatenate 'string
  17. (loop for x below max-y collect
  18. (elt (nth x padded-list) y)))))))
  19.  
  20. (defun split-seq (seq splitp)
  21. (loop
  22. for start = (position-if-not splitp seq)
  23. then (position-if-not splitp seq :start (1+ end))
  24. for end = (position-if splitp seq)
  25. then (position-if splitp seq :start start)
  26. if start collect (subseq seq start end)
  27. while end))
  28.  
  29. (defun split-lines (seq)
  30. (split-seq seq (lambda (x) (char= x #\Newline))))
  31.  
  32. (defun print-string-list (string-list)
  33. (format t "~{~a~%~}~%" string-list))
  34.  
  35. (defvar *challenge-input-1* "Some
  36. text.")
  37.  
  38. (defvar *challenge-input-2* "package main
  39.  
  40. import \"fmt\"
  41.  
  42. func main() {
  43. queue := make(chan string, 2)
  44. queue <- \"one\"
  45. queue <- \"twoO\"
  46. close(queue)
  47. for elem := range queue {
  48. fmt.Println(elem)
  49. }
  50. }")
  51.  
  52. (let ((split-input-1 (split-lines *challenge-input-1*))
  53. (split-input-2 (split-lines *challenge-input-2*)))
  54. (format t "Input 1:~%")
  55. (print-string-list split-input-1)
  56. (format t "Output 1:~%")
  57. (print-string-list (transpose-text split-input-1))
  58. (format t "Input 2:~%")
  59. (print-string-list split-input-2)
  60. (format t "Output 2:~%")
  61. (print-string-list (transpose-text split-input-2)))
Success #stdin #stdout 0.02s 10568KB
stdin
Standard input is empty
stdout
Input 1:
Some
text.

Output 1:
St
oe
mx
et
 .

Input 2:
package main
import "fmt"
func main() {
	queue := make(chan string, 2)
	queue <- "one"
	queue <- "twoO"
	close(queue)
	for elem := range queue {
	    fmt.Println(elem)
	}
}

Output 2:
pif							}
amuqqqcf }
cpnuuulo
koceeeor
ar uuus
gtmeeeeef
e a   (lm
 "i:<<qet
mfn=--um.
am(   e P
it)m""u:r
n" aote=i
  {knw) n
   eeo rt
   ("O al
   c " nn
   h   g(
   a   ee
   n    l
       qe
   s   um
   t   e)
   r   u
   i   e
   n
   g   {
   ,

   2
   )