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 trampoline(f): | |
| def _wrapped(*args, **kwargs): | |
| x = f(*args, **kwargs) | |
| while callable(x): | |
| x = x() | |
| return x | |
| return _wrapped | |
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 infix [form] | |
| (let [init (cons (second form) (cons (first form) (drop 2 form)))] | |
| (for [x init] (if (list? x) `(infix ~x) x)))) | |
| (infix ('(1 2) conj 0)) ; works as expected, even using lists as operands... |
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
| (defn avg [xs] (/ (apply + xs) (count xs))) | |
| (defn timed | |
| "Returns a function returning a two element vector with the execution time of f | |
| as the first element and the original result as the second" | |
| [f] | |
| (fn [& args] | |
| (let [start (. System (nanoTime)) | |
| res (apply f args)] | |
| > [(/ (double (- (. System (nanoTime)) start)) 1000000.0) res]))) | |
| (defn timed-sink |
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 null? (x) | |
| (eq nil x)) | |
| ;; (advice-add 'cider-refresh :around #'custom-cider-refresh) | |
| (defun cider-repl-open-current-ns () | |
| (interactive) | |
| (cider-find-ns nil (cider-current-ns))) | |
| (global-set-key (kbd "C-c m") 'cider-repl-open-current-ns) | |
| (defun cider-test-get-current-file-test-ns () |
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
| """ | |
| Analyze permutations by counting elements in correct positions (fixed points). | |
| """ | |
| import argparse | |
| from itertools import permutations | |
| from collections import defaultdict | |
| from math import factorial | |
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
| """ | |
| Analyze permutations by counting elements in correct positions (fixed points). | |
| """ | |
| import argparse | |
| from itertools import permutations | |
| from collections import defaultdict | |
| from math import factorial | |