Skip to content

Instantly share code, notes, and snippets.

@ArcAster
Created September 21, 2016 23:16
Show Gist options
  • Save ArcAster/d1e5f0cafb0f6e017bc8c315d5f41846 to your computer and use it in GitHub Desktop.
Save ArcAster/d1e5f0cafb0f6e017bc8c315d5f41846 to your computer and use it in GitHub Desktop.
#| (defunc max-ident-sublist (l)
:input-contract (listp l)
:output-contract (natp (max-ident-sublist l))
(if (endp l)
nil
(let ((maxRest (max-ident-sublist blah))
(maxTser (max-ident-sublist blah2)))
(if (> maxRest maxTser)
maxRest
maxTser))))
|#
;; count occurrence of n in l
;; for now this is going to return mode of list
(defunc occur (l n)
:input-contract (and (listp l) (not (listp n)))
:output-contract (natp (occur l n))
(if (endp l)
0
(if (equal (first l) n)
(+ 1(occur (rest l) n))
(occur (rest l) n))))
#|
;;max in list
(defunc maxlist (l)
:input-contract (listp l)
:output-contract (natp (maxList l))
(if (endp l)
0
(if (let (a (first l)) (b (first (rest l)))
(if (a > b)
|#
(defunc del (a l)
:input-contract (listp l)
:output-contract (listp (del a l))
(cond ((endp l) nil)
((equal a (first l)) (del a (rest l)))
(t (cons (first l) (del a (rest l))))))
#|
(defunc alet (n)
:input-contract (natp n)
:output-contract (natp (alet n))
(let ((a (+ n 1)) (b (+ n 2)))
a))
;; create list of occurences of elements in list
(defunc occurList (l)
:input-contract (listp l)
:output-contract (listp (occurList l))
(if (endp l)
nil
(if (equal (remove-dups l) nil)
nil
(cons (occur l (first (remove-dups l))) (occurList (rest l))))))
####
(let ((noDeps (remove-dups l)) (cleanList (del (first (remove-dups l)) l)))
|#
(defunc occurList (l)
:input-contract (listp l)
:output-contract (listp (aLet l))
(if (endp l)
nil
(if (equal (remove-dups l) nil)
nil
(let ((a (remove-dups l)))
if (endp a)
nil
(cons (occur l (first a)) (occur l (first (rest a))))))))
#|
(check= (max-ident-sublist '(1 2 3 3 3 4)) 3)
(check= (max-ident-sublist '(a c b b c d c)) 2)
(check= (max-ident-sublist nil) 0)
|#
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment