Created
May 13, 2015 00:08
-
-
Save zeptometer/478d73ef204fa34a139e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (defun solve-1-dolist (l) | |
| (let ((x 0)) | |
| (dolist (e l x) (setf x (+ x e))))) | |
| (defun solve-1-loop (l) | |
| (loop for e in l | |
| sum e)) | |
| (defun solve-1-recur (l &optional (sum 0)) | |
| (if (null l) | |
| sum | |
| (solve-1-recur (cdr l) (+ (car l) sum)))) | |
| (defun solve-2 (l r) | |
| (loop for e in l | |
| for f in r | |
| collect e | |
| collect f)) | |
| (defun solve-3 (&optional (n 100) (l (list 1 0))) | |
| (if (<= n 2) | |
| (reverse l) | |
| (solve-3 (1- n) (cons (+ (car l) (cadr l)) l)))) | |
| (defun solve-4 (l) | |
| (reduce (lambda (x y) (format nil "~a~a" x y)) | |
| (sort (mapcar (lambda (x) (format nil "~a" x)) l) #'string>=))) | |
| (defun n2l (n) | |
| (iter (repeat 8) | |
| (for x first n then (floor x 3)) | |
| (collect (aref (vector #'+ #'- nil) (mod x 3))))) | |
| (defun evaluate (ans op st rest ops) | |
| (cond ((null ops) (funcall op ans st)) | |
| ((null (car ops)) (evaluate ans op (+ (* 10 st) (car rest)) (cdr rest) (cdr ops))) | |
| (t (evaluate (funcall op ans st) (car ops) (car rest) (cdr rest) (cdr ops))))) | |
| (defun print-exp (l) | |
| (format t "1") | |
| (iter (for x from 2 to 9) | |
| (for op in l) | |
| (when (eq op #'+) (format t "+")) | |
| (when (eq op #'-) (format t "-")) | |
| (format t "~a" x)) | |
| (format t "~%")) | |
| (defun solve-5 () | |
| (iter (for x from 0 to (1- (expt 3 8))) | |
| (for l next (n2l x)) | |
| (when (= (evaluate 0 #'+ 1 '(2 3 4 5 6 7 8 9) l) 100) | |
| (print-exp l)))) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment