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
| (defmacro defmem | |
| [name parms & body] | |
| (let [fname (gensym) memname (gensym)] | |
| `(do (declare ~name) | |
| (letfn [(~fname ~parms ~@body)] | |
| (let [~memname (atom {})] | |
| (defn ~name ~parms | |
| (if (contains? @~memname ~parms) | |
| (get @~memname ~parms) | |
| (do (swap! ~memname assoc ~parms (~fname ~@parms)) |
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 nfib (a b c n) | |
| (if (= n 0) | |
| a | |
| (nfib b c (/ (+ b c) a) (1- n)))) | |
| (defmacro while (test &body body) | |
| `(do () | |
| ((not ,test)) | |
| ,@body)) |
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
| (defmacro while (test &body body) | |
| `(do () | |
| ((not ,test)) | |
| ,@body)) | |
| (defmacro with-gensyms (syms &body body) | |
| `(let ,(mapcar #'(lambda (x) `(,x (gensym))) syms) | |
| ,@body)) | |
| (defmacro collect-list (end-condition next-value var) |
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
| def swap_max(digits): | |
| i = len(digits) - 1 | |
| while i > 0: | |
| if digits[i] == 0: | |
| i-= 1 | |
| else: | |
| break | |
| max_i = i | |
| min_i = i | |
| pot_i = i |
NewerOlder