fork(1) download
  1. ;; //ideone.com/vzncKq
  2.  
  3. (defstruct point x y)
  4.  
  5. (defun point+ (p q)
  6. (make-point :x (+ (point-x p) (point-x q))
  7. :y (+ (point-y p) (point-y q))))
  8.  
  9. (defun make-point-from-char (c)
  10. (ecase c
  11. (#\> (make-point :x 1 :y 0))
  12. (#\v (make-point :x 0 :y 1))
  13. (#\< (make-point :x -1 :y 0))
  14. (#\^ (make-point :x 0 :y -1))))
  15.  
  16. (defun draw (chars)
  17. (let ((scr (make-hash-table :test #'equalp)))
  18. (loop for char across chars
  19. for p = (make-point :x 0 :y 0)
  20. then (point+ p (make-point-from-char char))
  21. do (setf (gethash p scr) char))
  22. ;;
  23. (destructuring-bind (min-x min-y
  24. max-x max-y)
  25. (loop for point being the hash-keys in scr using (hash-value char)
  26. maximize (point-x point) into max-x
  27. maximize (point-y point) into max-y
  28. minimize (point-x point) into min-x
  29. minimize (point-y point) into min-y
  30. finally (return (list min-x min-y
  31. max-x max-y)))
  32. (loop for y from min-y upto max-y
  33. do (loop for x from min-x upto max-x
  34. for c = (gethash (make-point :x x :y y) scr)
  35. do (princ (or c #\*)))
  36. (terpri)))))
  37.  
  38. (loop while (listen)
  39. do (draw (read-line))
  40. (terpri))
  41.  
Success #stdin #stdout 0s 203840KB
stdin
>>>>>vvvvv<<<<^^^^
<<<<^^^^>>>>>vv<<<<<<<<<<<vvv>>>^^^^^^^>>>>>>>>>>vvvvvv
stdout
>>>>>
^***v
^***v
^***v
^***v
<<<<v

***^>>>>>>>>>>
***^*********v
***^**^>>>>>*v
***^**^****v*v
<<<^<<<<<<<v*v
v**^**^******v
v**^**<<<<***v
v>>>**********