Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
18
Task/Rep-string/Common-Lisp/rep-string-1.lisp
Normal file
18
Task/Rep-string/Common-Lisp/rep-string-1.lisp
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
(ql:quickload :alexandria)
|
||||
(defun rep-stringv (a-str &optional (max-rotation (floor (/ (length a-str) 2))))
|
||||
;; Exit condition if no repetition found.
|
||||
(cond ((< max-rotation 1) "Not a repeating string")
|
||||
;; Two checks:
|
||||
;; 1. Truncated string must be equal to rotation by repetion size.
|
||||
;; 2. Remaining chars (rest-str) are identical to starting chars (beg-str)
|
||||
((let* ((trunc (* max-rotation (truncate (length a-str) max-rotation)))
|
||||
(truncated-str (subseq a-str 0 trunc))
|
||||
(rest-str (subseq a-str trunc))
|
||||
(beg-str (subseq a-str 0 (rem (length a-str) max-rotation))))
|
||||
(and (string= beg-str rest-str)
|
||||
(string= (alexandria:rotate (copy-seq truncated-str) max-rotation)
|
||||
truncated-str)))
|
||||
;; If both checks pass, return the repeting string.
|
||||
(subseq a-str 0 max-rotation))
|
||||
;; Recurse function reducing length of rotation.
|
||||
(t (rep-stringv a-str (1- max-rotation)))))
|
||||
15
Task/Rep-string/Common-Lisp/rep-string-2.lisp
Normal file
15
Task/Rep-string/Common-Lisp/rep-string-2.lisp
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
(setf test-strings '("1001110011"
|
||||
"1110111011"
|
||||
"0010010010"
|
||||
"1010101010"
|
||||
"1111111111"
|
||||
"0100101101"
|
||||
"0100100"
|
||||
"101"
|
||||
"11"
|
||||
"00"
|
||||
"1"
|
||||
))
|
||||
|
||||
(loop for item in test-strings
|
||||
collecting (cons item (rep-stringv item)))
|
||||
Loading…
Add table
Add a link
Reference in a new issue