Balanced brackets: Difference between revisions
Content added Content deleted
m (Reduced some redundant expressions in the section of Common Lisp) |
|||
Line 1,722: | Line 1,722: | ||
<lang lisp> |
<lang lisp> |
||
(defun string-of-brackets (n) |
(defun string-of-brackets (n) |
||
(let (( |
(let* ((len (* 2 n)) |
||
( |
(res (make-string len)) |
||
( |
(opening (/ len 2)) |
||
(closing (/ len 2))) |
|||
(dotimes (i len res) |
|||
(setf (aref res i) |
|||
(cond ((zerop opening) #\]) |
|||
((zerop closing) #\[) |
((zerop closing) #\[) |
||
(t (if (= (random 2) 0) |
(t (if (= (random 2) 0) |
||
(progn (decf opening) #\[) |
(progn (decf opening) #\[) |
||
(progn (decf closing) #\])))))))) |
(progn (decf closing) #\])))))))) |
||
(defun balancedp (string) |
(defun balancedp (string) |