Skip to content

Instantly share code, notes, and snippets.

@doug-wade
Created August 15, 2013 21:42
Show Gist options
  • Save doug-wade/6245234 to your computer and use it in GitHub Desktop.
Save doug-wade/6245234 to your computer and use it in GitHub Desktop.
errata
(setf nerd-states '(sleeping eating waiting-for-a-computer programming debugging))
(defun nerdus (state)
(if (equal (last nerd-states) (list state))
(first nerd-states)
(second (member state nerd-states))
)
)
(defun sleepless-nerd (state)
(if (equal (last nerd-states) (list state))
(second nerd-states)
(second (member state nerd-states))
)
)
;Testing
;(print (nerdus 'sleeping))
;(print (nerdus 'eating))
;(print (nerdus 'waiting-for-a-computer))
;(print (nerdus 'programming))
;(print (nerdus 'debugging))
;(print (sleepless-nerd 'sleeping))
;(print (sleepless-nerd 'eating))
;(print (sleepless-nerd 'waiting-for-a-computer))
;(print (sleepless-nerd 'programming))
;(print (sleepless-nerd 'debugging))
(defun left-side (list-to-split)
(reverse (set-difference (member '-vs- (reverse list-to-split)) '(-vs-)))
)
(defun right-side (list-to-split)
(set-difference (member '-vs- list-to-split) '(-vs-))
)
(defun count-common (list-one list-two)
(length (intersection list-one list-two))
)
(defun compare (list-of-objects)
(count-common (left-side list-of-objects) (right-side list-of-objects))
)
(print (compare '(small red metal cube -vs- red plastic small cube)))
(defun last-element1 (L)
(car (last L))
)
(defun last-element2 (L)
(first (reverse L))
)
(defun last-element3 (L)
(nth (- (length L) 1) L)
)
(defun next-to-last1 (L)
(second (reverse L))
)
(defun next-to-last2 (L)
(nth (- (length L) 2) L)
)
(defun my-butlast (L)
(reverse (nthcdr 1 (reverse L)))
)
(defun palindromep (L)
(equal L (reverse L))
)
(defun make-palindrome (L)
(if (palindromep L)
L
(append L (reverse L))
)
)
(defun contains-article-p1 (L)
(intersection L '(a an the))
)
(defun contains-article-p2 (L)
(or (member 'a L) (member 'an L) (member 'the L))
)
(defun contains-article-p3 (L)
(not (and (not(member 'a L)) (not(member 'an L)) (not(member 'the L))))
)
(defun add-vowels (L)
(union '(a e i o u) L)
)
(defun my-subsetp (containingset subset)
(equal nil (set-difference subset containingset))
)
(defun set-equal (L1 L2)
(not (or (set-difference L1 L2) (set-difference L2 L1)))
)
(defun proper-subsetp (L1 L2)
(and (not (set-equal L1 L2)) (subset L1 L2))
)
(defun who-wrote (x booklist)
(last (assoc x booklist))
)
(defun swap-first-last (list-to-swap)
(let ((last-temp (car (last list-to-swap)))
(first-temp (first list-to-swap)))
(setf (nth 0 list-to-swap) last-temp)
(setf (nth (- (length list-to-swap) 1) list-to-swap) first-temp)
)
list-to-swap
)
(defun rotate-left (list-to-rotate)
(let ((first-temp (first list-to-rotate)))
(append (member (second list-to-rotate) list-to-rotate) (list first-temp))
)
)
(defun rotate-right (list-to-rotate)
(reverse (rotate-left (reverse list-to-rotate)))
)
;On page 187 (printed 175)
;Tests
;(setf test-list '(1 2 3 4))
;(print (last-element1 test-list))
;(print (last-element2 test-list))
;(print (last-element3 test-list))
;(print (next-to-last1 test-list))
;(print (next-to-last2 test-list))
;(print (palindromep test-list))
;(print (palindromep '(1 2 3 2 1)))
;(print (make-palindrome test-list))
;(print (make-palindrome '(1 2 3 2 1)))
;(print (my-butlast test-list))
;(print (contains-article-p3 '(this is the remix)))
;(print (contains-article-p3 '(your mother)))
;(setf book-list '((war-and-peace leo-tolstoy)
; (three-sisters anton-checkov)
; (evegenii-onegin aleksandr-pushkin)
; (master-and-margarita mikhail-bulgakov)
; (foundation-pit andrei-platonov))
;)
;(print (who-wrote 'war-and-peace book-list))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment