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 numbers | |
[[" - " | |
"| |" | |
" " | |
"| |" | |
" - "] | |
[" " | |
" |" | |
" " |
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 vice | |
(:require [clojure.spec :as s] | |
[clj-time.core :as t] | |
[clj-time.format :as tf]) | |
(:import [org.joda.time DateMidnight DateTime] | |
[java.util UUID] | |
[clojure.lang Keyword] | |
[java.math BigInteger] | |
[java.net URL URI] | |
[java.util.regex Pattern])) |
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 merge-with-key | |
[f & maps] | |
(when (some identity maps) | |
(reduce (fn [acc x] | |
(reduce (fn [m [k v]] | |
(if (contains? m k) | |
(assoc m k (f k (get m k) v)) | |
(assoc m k v))) | |
acc | |
x)) |
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 sudoku | |
(:require [clojure.set :as set])) | |
(defn row-values | |
[board [row _]] | |
(set (get board row))) | |
(defn- transpose | |
[matrix] | |
(vec (apply map vector matrix))) |
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 map-matrix | |
[f colls] | |
(vec (map-indexed (fn [y row] | |
(vec (map-indexed (fn [x value] | |
(f value x y)) | |
row))) | |
colls))) |
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 solve | |
[grid] | |
(remove nil? | |
(run* [q] | |
(macro/symbol-macrolet [_ (lvar)] | |
(== q grid) | |
(conde | |
((== grid [[q _ _] | |
[_ q _] | |
[_ _ q]])) |
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
(use '[clojure.string :only (join)]) | |
(defn coder | |
[dictionary] | |
(let [mnemonics {\2 "ABC" \3 "DEF" \4 "GHI" \5 "JKL", | |
\6 "MNO" \7 "PQRS" \8 "TUV" \9 "WXYZ"} | |
char-code (into {} (mapcat (fn [[n cs]] | |
(map #(vector % n) cs)) | |
mnemonics)) |
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
let rec cycle xs = | |
Seq.concat (Seq.initInfinite (fun _ -> xs)) | |
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 core | |
(:use quil.core)) | |
(defn tick | |
[state] | |
(let [neighbors (fn [x y] | |
(for [xinc (range -1 (inc 1)) | |
yinc (range -1 (inc 1)) :when (not (= 0 xinc yinc))] | |
[(+ x xinc) (+ y yinc)])) | |
map-matrix (fn [f matrix] |
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
;; without numbers | |
(def fizzbuzz | |
(let [fizz (cycle [nil nil "fizz"]) | |
buzz (cycle [nil nil nil nil "buzz"])] | |
(remove empty? (map str fizz buzz)))) | |
;; with numbers | |
(defn fizzbuzz | |
[n] | |
(let [xs (range 1 (inc n)) |
NewerOlder