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
#!/bin/bash | |
# launch a clojure plain repl but with options and classpath matching project.clj | |
# Except when project.clj changes (and on first launch), lein is not called. | |
if [ ! -f "project.clj" ]; then | |
echo "No project.clj" | |
exit 1 | |
fi | |
# stat (mostly) protects against staleness of copied project dir |
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 miner.pal | |
(:require [criterium.core :as crit] | |
[clojure.string :as str])) | |
;; An exercise from Apropos Clojure #18 video cast: | |
;; https://www.youtube.com/watch?v=elF9BPa0Np4 | |
;; | |
;; Their solution is something like this... |
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
;; map-alt is like the map xform but calls the funtions in an alternating order | |
;; (f i0) (g i1) (h i2) (f i3) ... | |
;; | |
;; In other words, map-alt spreads fn calls across elements, whereas (mapcat (juxt ...)) calls all | |
;; fns on each element. | |
(defn map-alt | |
([] (map identity)) | |
([f] (map f)) |
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 digits [n] | |
{:pre [(int? n) (>= n 0)]} | |
(loop [digs () remainder n] | |
(if (< remainder 10) | |
(conj digs remainder) | |
(recur (conj digs (rem remainder 10)) (quot remainder 10))))) | |
(defn digits+rev [n] | |
(let [ds (digits n)] | |
(concat ds (reverse ds)))) |
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 miner.infix) | |
;; Inspired by the excellent book "The Joy of Clojure". | |
;; http://fogus.me/fun/unfix/infix-src.html | |
;; | |
;; Converted to be used as a data-reader by Steve Miner. The main change is to preserve | |
;; the prefix forms rather than calculating the result. Also, the reader gets symbols, not | |
;; the actual functions. | |
(def && #(and % %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
(ns miner.roman | |
(:require [clojure.test :refer :all])) | |
;; inspired by | |
;; http://www.jayway.com/2012/08/04/a-decimal-to-roman-numeral-converter-in-just-a-few-lines/ | |
(def roman-map {1000 "M" 900 "CM" 500 "D" 400 "CD" | |
100 "C" 90 "XC" 50 "L" 40 "XL" | |
10 "X" 9 "IX" 5 "V" 4 "IV" 1 "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 sudoku | |
(:refer-clojure :exclude [==]) | |
(:use clojure.core.logic)) | |
(defn get-square [rows x y] | |
(for [x (range x (+ x 3)) | |
y (range y (+ y 3))] | |
(get-in rows [x y]))) | |
(defn init [vars hints] |
NewerOlder