This file contains 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 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 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 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 |
This file contains 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
(ns test-sketch.core | |
(:require [quil.core :as q] | |
[quil.middleware :as m]) | |
(:gen-class)) | |
(import megamu.mesh.Voronoi) | |
(def minr 10) | |
(def maxr 100) |
This file contains 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
;; gorilla-repl.fileformat = 1 | |
;; ** | |
;;; #Clojure Report | |
;; ** | |
;; @@ | |
(ns clojure-report.clojure-report | |
(:require [gorilla-plot.core :as plot]) | |
(:require [clojure.core.typed :as t])) |
This file contains 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
1 3 4 5 7 8 2 3 4 9 | |
20 30 | |
45 | |
108 202 |
This file contains 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 increment-counter [res word] | |
(update-in res [word] (fnil inc 0))) | |
(defn increment-link [dict word1 word2] | |
(update-in dict [word1] increment-counter word2)) | |
(defn split-text [text] | |
(filter #(not (re-matches #"\s+" %)) (clojure.string/split text #"[.!?>\-\"\*\)\(]"))) | |
(defn fix-sentences [sentences] |
This file contains 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
class Literal: | |
def __init__(self,value): | |
self.value = value | |
class State: | |
def __init__(self,oldstate=None): | |
if(oldstate != None): | |
self.oldstate = [oldstate] | |
else: | |
self.oldstate = [] |
This file contains 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 iterator-from-combos (&rest lists) | |
"Takes a set of lists, and returns an iterator that iterates through every | |
possible combo of values where each value is from the list passed at its | |
index." | |
(if (contains nil lists) ;; If any of the passed lists are nil, no combos can be made. | |
(lambda () (values nil t)) ;; There are no combos, return an empty iterator. | |
(labels ;; Otherwise, build the combos iterator. | |
((shift (lists base) ;; Shifts the set of lists down by one. | |
;; Returns two values, the new lists, and whether we have hit the end | |
(if (not lists) ;; If no lists have been passed, we are done shifting. |
NewerOlder