Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (defun flatten (list)
- (cond ((null list) nil)
- ((consp (car list)) (append (flatten (car list)) (flatten (cdr list))))
- (t (cons (car list) (flatten (cdr list))))))
- (defun deep-reverse (list)
- (labels ((deep (list copy)
- (cond ((null list) copy)
- ((consp (car list)) (deep (cdr list) (cons (deep-reverse (car list)) copy)))
- (t (deep (cdr list) (cons (car list) copy)))
- )))
- (deep list '())))
- ;;(let ((x 1)) (let ((x (- x 10)) (y (1+ x))) y))
- ;;let ((x 1)) (let* ((x (- x 10)) (y (1+ x))) y))
- (defun blabla (x)
- (if (consp x)
- (cons (blabla (cdr x))
- (blabla (car x)))
- x))
- (defun tailz (list)
- (cond ((null list) (cons nil nil))
- (t (cons list (tailz (cdr list)))
- )))
- (defun new-from-two (seq)
- (lambda (x) (* (funcall seq x) (funcall seq (1+ x)))))
- (defun all-intervals (start end)
- (cond ((> start end) nil)
- (t (append (func start end start) (all-intervals (1+ start) end)))))
- (defun func (start end count)
- (cond ((> count end) nil)
- (t (cons (cons start count) (func start end (1+ count))))))
- (defun tree-height (tree)
- (cond ((null tree) 0)
- (t (1+ (max-height-children (cdr tree))))
- ))
- (defun max-height-children (children)
- (cond ((null children) -1)
- (t (max (tree-height (car children)) (max-height-children (cdr children))))))
- ;;(defun spiral (length count)
- ;; (cond ((<= count 0) 0)
- ;; (t (progn (turtle:draw length) (turtle:turn pi/2) (spiral (* (/ 3 4) length) (1- count))))))
- (defun last-n (list n)
- (let ((res (hilfe list list n)))
- (cond ((>= (cdr res) n) (car res))
- (t (- n (cdr res))))))
- ;; ( (0 1 2 3 4) . 5)
- (defun hilfe(orig list n)
- (cond ((null list) (cons nil 0))
- (t (let ((next (hilfe orig (cdr list) n)))
- (cond ((>= (cdr next) n) next)
- (t (cons (cons (car list) (car next)) (1+ (cdr next)))))))))
- (defun last-nn (list n)
- (cond ((null list) n)
- ((= n 0) nil)
- ((= n 1) list)
- (t (last-nn (cdr list) (- n 1)))))
- (defun last-nnn (list n)
- (cond ((null list) n)
- ((= n 0) nil)
- ((> n (length list)) (- n (length list)))
- (t (iter list (- (length list) n)))))
- (defun iter (list x)
- (if (> x 0)
- (iter (cdr list) (- x 1))
- list))
- (defun tbl-test (row col)
- (* row (+ col 1)))
- (defun zero-row-p (tbl row)
- (labels ((test (col) (or (> col 9)
- (and (= 0 (funcall tbl row col))
- (test (1+ col))))))
- (test 0)))
- (defun fandom (fun)
- (let ((rnd (random 100)))
- (if (funcall fun rnd) rnd (fandom fun))
- ))
- (defun interleave (a b)
- (cond ((null a) b)
- ((null b) a)
- (t (cons (car a) (interleave b (cdr a))))))
- (defun pascal (col row)
- (cond ((= 0 col) 1)
- ((= col row) 1)
- (t (+ (pascal (1- col) (1- row)) (pascal col (1- row))))))
- (defun pascal-row (row)
- (labels ((lokal (col)
- (cond ((> col row) nil)
- (t (cons (pascal col row) (lokal (1+ col)))))))
- (lokal 0)))
- (defun first-less (seqA seqB)
- (labels ((test (x) (cond ((< (funcall seqA x) (funcall seqB x)) x)
- (t (test (1+ x))))))
- (test 0)))
- (defun max-path♥♥ (tree)
- (car (max-path♥ tree)))
- (defun max-path♥ (tree)
- (cond ((null tree) (cons nil -1))
- (t (let ((children (max-path-children (cdr tree) (cons nil -1))))
- (cons (cons (car tree) (car children)) (1+ (cdr children)))
- ))))
- (defun max-path-children (children max)
- (cond ((null children) max)
- (t (let ((child (max-path♥ (car children))))
- (if (< (cdr max) (cdr child))
- (max-path-children (cdr children) child )
- (max-path-children (cdr children) max))))))
- ;;(let ((x 5))(print x)(x))
- ;;(countz '(1 (2 3) 4) )
- (defun countz (list)
- (cond ((consp list) (+ (countz (car list))
- (countz (cdr list))))
- ((null list) (progn (print list) 1))
- (t 0)))
- (defun each-2nd (list)
- (labels ((♥♥♥ (list c)
- (cond ((null list) nil)
- ((evenp c) (cons (car list) (♥♥♥ (cdr list) (1+ c))))
- (t (♥♥♥ (cdr list) (1+ c))))))(♥♥♥ list 1)))
- (defun trianglep (a b c)
- (> (+ a b c) (* 2 (max a b c))))
- (defun digit-count (x) (digit-count-internal x 0))
- (defun digit-count-internal (x count)
- (if (< x 1) count (digit-count-internal (/ x 10) (+ count 1))))
- ;;Returns the digit at Nth position from the right without using mod/rem, starts from 1
- (defun digit (x n)
- (floor (* (- (/ x (power 10 (1+ n)))
- (floor (/ x (power 10 (1+ n)))) ) 10)) )
- ;;12
- (defun power (x n) (power-internal x n 1))
- (defun power-internal (x n res) (if (> n 0) (power-internal x (- n 1) (* res x)) res))
- (defun digit-sum (x) (digit-sum-internal x (digit-count x) 0 0))
- (defun digit-sum-internal (x length pos sum)
- (if (> pos length) sum (digit-sum-internal x length (+ pos 1) (+ sum (digit x pos)))))
- ;;Uses digit-sum --> see 5 lines above
- ;;(defun multiply-of-9-internal-p (x) (if (>= x 10) (multiply-of-9-internal-p (digit-sum x)) (= x 9) ))
- ;;(defun multiply-of-9-p (x) (multiply-of-9-internal-p (digit-sum x)))
- (defun notsofunnyfunc (x)
- (cond ((> x 9) (notsofunnyfunc (digit-sum x)))
- ((> x 0) (notsofunnyfunc (- x 3)))
- ((= x 0) t)
- (t nil)))
- (defun pp (x)
- (or (and (> x 9) (pp (digit-sum x)))
- (and (> x 0) (pp (- x 3)))
- (= x 0)))
- (defun lidl (predi list)
- (and (not (null list)) (or (funcall predi (car list)) (lidl predi (cdr list)))))
- (defun my-signum (x)
- (signum x))
- (defun euler (n)
- (labels ((phun (x denom) (cond ((> x n) 0)
- (t (+ (/ 1 (* x denom)) (phun (1+ x) (* x denom))))))) (* 1.0 (1+ (phun 1 1)))))
- (defun same-sums-p (list)
- (apply #'= (mapcar #'sumsum list)))
- (defun sumsum (list)
- (apply #'+ list))
- (defun prefix-to-infox (input)
- (cond ((<= (length input) 2) input)
- (t (infixee (car input) (cdr input)))))
- (defun infixee (op args)
- (cond ((null (cdr args)) (cons (car args) nil))
- (t (cons (car args) (cons op (infixee op (cdr args)))))))
- (defun seq-shift (seq shift)
- (lambda (x) (if (< (+ x shift) 0) 0 (funcall seq (+ x shift)))))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement