Skip to content

Instantly share code, notes, and snippets.

@ArcAster
Created September 22, 2016 00:53
Show Gist options
  • Select an option

  • Save ArcAster/847b3aa05e270a4e94e9a9543da88737 to your computer and use it in GitHub Desktop.

Select an option

Save ArcAster/847b3aa05e270a4e94e9a9543da88737 to your computer and use it in GitHub Desktop.

Revisions

  1. ArcAster created this gist Sep 22, 2016.
    108 changes: 108 additions & 0 deletions wtf
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,108 @@
    #| (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 (listp l)
    :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 delAll (a l)
    :input-contract (listp l)
    :output-contract (listp (delAll a l))
    (cond ((endp l) nil)
    ((equal a (first l)) (delAll a (rest l)))
    (t (cons (first l) (delAll 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 (occurList l))
    (if (endp l)
    nil
    (if (equal (delAll (first l) l) nil)
    nil
    (cons (occur l (first l)) (occurList (delAll (first l) l))))))

    (defunc ocList (l l1)
    :input-contract (and (listp l) (listp l1))
    :output-contract (listp (ocList l l1))
    (if (or (endp l) (endp l1))
    nil
    (cons (occur l (first l1)) (ocList l (rest l1)))))

    (defunc ocList2 (l)
    :input-contract (listp l)
    :output-contract (listp (ocList2 l))
    (if (endp l)
    nil
    (ocList l (remove-dups l))))


    (defunc max (a b)
    :input-contract (and (natp a) (natp b))
    :output-contract (natp (max a b))
    (if (< a b) b a))

    (defdata rationallist (listof rational))
    (defdata natlist (listof nat))

    (defunc maxList (l)
    :input-contract (natlistp l)
    :output-contract (natp (maxList l))
    (if (or (endp l) (equal (rest l) nil))
    0
    (if (< (first l) (first (rest l)))
    (maxList (rest l))
    (first l))))

    (defunc max-ident-list (l)
    :input-contract (listp l)
    :output-contract (natp (max-ident-list l))
    (maxList (ocList2 l)))