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.lucky | |
(:require [clojure.data.avl :as avl])) | |
;; http://en.wikipedia.org/wiki/Lucky_number | |
(defn lucky-avl | |
([max] (lucky-avl 1 (apply avl/sorted-set (range 1 max 2)))) | |
([i avl] | |
(let [n (nth avl i nil)] | |
(if (and n (<= n (count avl))) |
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
;; I posted an earlier version on my blog: | |
;; http://fnclojure.wordpress.com/2012/08/06/roman-numerals-in-clojure/ | |
;; This version is faster and more readable. | |
(defn range-down | |
"Returns a seq of integers from HIGH (exclusive) down to LOW (inclusive). | |
LOW defaults to 0. STEP is a positve decrement, defaults to 1. Like | |
`(reverse (range low high step))' but a bit faster." | |
([high] (range (dec high) -1 -1)) |
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
;;; 01/14/14 16:18 by miner -- Steve Miner revised this code to be more idiomatic Clojure. | |
;;; | |
; Short sidebar: Clojure has a special form for the efficient compilation of tail recursion. | |
; Something like this would work as a factorial function: | |
(defn fact2 [n] | |
(loop [n n acc 1] | |
(if (zero? n) acc (recur (dec n) (* n acc))))) | |
; We're not going to discuss `recur` any further as we're imagining a language that doesn'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
;; inspired by https://twitter.com/puredanger/status/241282082268143619 | |
;; reduce-kv is faster than destructuring with maps | |
;; use (get m k) instead of (k m) to be safe with non-keyword keys | |
(defn sub= | |
"Like = for most things, but maps compare recursively by only the keys in a, so it returns true | |
if a is a 'submap' of b." | |
[a b] | |
(if (and (map? a) (map? b)) |
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
;; http://rosettacode.org/wiki/Four_bit_adder | |
(ns miner.fourbit) | |
;; a bit is represented as a boolean (true/false) | |
;; a word is a big-endian vector of bits [true false true true] = 11 | |
;; maybe little endian is more convenient??? | |
(defn bvec |
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
;;; http://johnj.com/from-elegance-to-speed.html | |
;;; | |
;;; The author of the above blog post says that his `smt-8` was slow so he re-wrote it in | |
;;; Common Lisp and got nearly 300x improvement. I wrote some pure Clojure variations | |
;;; showing much improved performance over the original. | |
;;; | |
;;; Criterium for benchmarking: https://github.com/hugoduncan/criterium/ | |
(ns miner.smt | |
(:require [criterium.core :as cc])) |
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 | |
# my git difftool, calls FileMerge with project as -merge target | |
# better than using opendiff | |
# | |
# cd to your project dir and and run difftool like this: | |
# git difftool -d -x gdiff | |
# find top level of git project | |
dir=$PWD | |
until [ -e "$dir/.git" ]; do |
OlderNewer