tasks a-s
This commit is contained in:
parent
47bf37c096
commit
b83f433714
12433 changed files with 156208 additions and 123 deletions
|
|
@ -0,0 +1,29 @@
|
|||
(defun count-and-say (str)
|
||||
(let* ((s (sort (map 'list #'identity str) #'char>))
|
||||
(out (list (first s) 0)))
|
||||
(loop for x in s do
|
||||
(if (char= x (first out))
|
||||
(incf (second out))
|
||||
(setf out (nconc (list x 1) out))))
|
||||
(format nil "~{~a~^~}" (nreverse out))))
|
||||
|
||||
(defun ref-seq-len (n &optional doprint)
|
||||
(let ((s (format nil "~d" n)) hist)
|
||||
(loop (push s hist)
|
||||
(if doprint (format t "~a~%" s))
|
||||
(setf s (count-and-say s))
|
||||
(loop for item in hist
|
||||
for i from 0 to 2 do
|
||||
(if (string= s item) (return-from ref-seq-len (length hist)))))))
|
||||
|
||||
(defun find-longest (top)
|
||||
(let (nums (len 0))
|
||||
(dotimes (x top)
|
||||
(let ((l (ref-seq-len x)))
|
||||
(if (> l len) (setf len l nums nil))
|
||||
(if (= l len) (push x nums))))
|
||||
(list nums len)))
|
||||
|
||||
(let ((r (find-longest 1000000)))
|
||||
(format t "Longest: ~a~%" r)
|
||||
(ref-seq-len (first (first r)) t))
|
||||
|
|
@ -0,0 +1,22 @@
|
|||
Longest: ((9900 9090 9009) 21)
|
||||
9900
|
||||
2920
|
||||
192210
|
||||
19222110
|
||||
19323110
|
||||
1923123110
|
||||
1923224110
|
||||
191413323110
|
||||
191433125110
|
||||
19151423125110
|
||||
19251413226110
|
||||
1916151413325110
|
||||
1916251423127110
|
||||
191716151413326110
|
||||
191726151423128110
|
||||
19181716151413327110
|
||||
19182716151423129110
|
||||
29181716151413328110
|
||||
19281716151423228110
|
||||
19281716151413427110
|
||||
19182716152413228110
|
||||
Loading…
Add table
Add a link
Reference in a new issue