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 vec-abs | |
[[x y]] | |
(+ (* x x) | |
(* y y))) | |
(defn vec-add | |
[x y] | |
(map + x y)) | |
(defn vec-sq |
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 massive-arity | |
[& [a b c d e f g h i j k l m n o p q r s t u v w x y z]] | |
(print a b c d e f g h i j k l m n o p q r s t u v w x y z)) |
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 different-int-pairs | |
"Generate all pairs of the integers [0,n), excluding those of the form [a,a] and only the first pair of the symmetric [a,b] [b,a]" | |
[n] | |
(mapcat (fn [x] (map #(vector x %) | |
(range (inc x) n))) | |
(range n))) |
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 cluster.core) | |
; Begin by creating 'clusters' for all the squares of a particular number | |
; Then repeatedly check for adjacent clusters and merge them | |
(defn random-grid | |
"A grid composed of random values in range [1,n]" | |
[size n] | |
(vec (map vec | |
(partition size | |
(repeatedly (* size size) | |
#(int (+ 1.5 (rand (dec n))))))))) |
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
from random import randint | |
# A grid of the specified size, composed of random values in range [1,n] | |
def random_grid(size, n): | |
return [[randint(0, (n - 1)) for _ in range(size)] for _ in range(size)] | |
# Generate all sets of integers pairs in [0,n), excluding those of the form [a a] | |
def int_pairs(n): | |
pairs = [] | |
for i in range(0, n): |
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 sokoban.core) | |
(def moves {:n [0 1] :s [0 -1] :e [1 0] :w [-1 0]}) | |
(def start-world | |
{:person [3 1] | |
:targets #{[1 3]} | |
:crates #{[1 2]} | |
:blanks #{[1 3] [2 3] [3 3] | |
[1 2] [2 2] [3 2] |
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
user=> (map #(partition 3 %) ["123---" "456---"]) | |
(((\1 \2 \3) (\- \- \-)) ((\4 \5 \6) (\- \- \-))) | |
user=> (map #(map (partial apply str) (partition 3 %)) ["123---" "456---"]) | |
(("123" "---") ("456" "---")) | |
user=> (map #(map (partial apply str) (partition 3 %)) s) ["123---" "456---"]) | |
CompilerException java.lang.RuntimeException: Unable to resolve symbol: s in this context, compiling:(NO_SOURCE_PATH:1:1) | |
["123---" "456---"] | |
RuntimeException Unmatched delimiter: ) clojure.lang.Util.runtimeException (Util.java:219) |
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
; A little function that adds its two parameters together | |
(defn addit [x y] (+ x y)) | |
; This adds the value supplied in the second parameter to the atom in the first parameter, then returns the atom | |
(defn atom-adder [x y] (swap! x (partial addit y)) x) | |
(def value-atom (atom 1)) | |
; Create an agent with a reference to the atom | |
(def counter-agent (agent value-atom)) |
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 sieve (atom [])) | |
(def siever (agent sieve)) | |
(send-off siever | |
(fn [x test-set] | |
(doall | |
(map (fn [n] | |
(if (not (some | |
#(zero? (mod n %)) |
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
import java.io.IOException; | |
import java.nio.file.FileVisitResult; | |
import java.nio.file.Files; | |
import java.nio.file.Path; | |
import java.nio.file.Paths; | |
import java.nio.file.SimpleFileVisitor; | |
import java.nio.file.attribute.BasicFileAttributes; | |
import org.apache.commons.lang3.StringUtils; |