Data update
This commit is contained in:
parent
5af6d93694
commit
796d366b97
455 changed files with 7413 additions and 1900 deletions
28
Task/Ordered-words/Acornsoft-Lisp/ordered-words.lisp
Normal file
28
Task/Ordered-words/Acornsoft-Lisp/ordered-words.lisp
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
(defun longest-ordered-words ()
|
||||
(find-longest-ordered-words
|
||||
(open 'notes/unixdict!.txt t)))
|
||||
|
||||
(defun find-longest-ordered-words
|
||||
(h (len . 0) (word) (words))
|
||||
(loop
|
||||
(until (eof h)
|
||||
(close h)
|
||||
words)
|
||||
(setq word (readline h))
|
||||
(cond ((lessp (chars word) len))
|
||||
((not (ordered-p word)))
|
||||
((eq (chars word) len)
|
||||
(setq words (cons word words)))
|
||||
(t
|
||||
(setq len (chars word))
|
||||
(setq words (list word))))))
|
||||
|
||||
(defun ordered-p (word)
|
||||
(nondecreasing-p
|
||||
(mapc ordinal (explode word))))
|
||||
|
||||
(defun nondecreasing-p (numbers)
|
||||
(or (null numbers)
|
||||
(null (cdr numbers))
|
||||
(and (not (greaterp (car numbers) (cadr numbers)))
|
||||
(nondecreasing-p (cdr numbers)))))
|
||||
Loading…
Add table
Add a link
Reference in a new issue