Skip to content

Instantly share code, notes, and snippets.

View miner's full-sized avatar

Steve Miner miner

View GitHub Profile
@miner
miner / gist:3240618
Created August 2, 2012 21:03 — forked from swannodette/gist:3217582
sudoku_compact.clj
(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]
@miner
miner / roman.clj
Created August 6, 2012 14:16
Roman Numerals
(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"})
@miner
miner / infix.clj
Last active June 26, 2016 13:27
An infix data-reader
(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))
@miner
miner / apropos3.clj
Created March 19, 2018 20:47
a stateful transducer inspired by @apropos_cast episode #3
(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))))
@miner
miner / map-alt.clj
Created March 14, 2018 19:28
map-alt transducer
;; 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))
@miner
miner / pal.clj
Created October 2, 2018 20:30
find longest palindromic substring using Clojure
(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...
@miner
miner / kein.sh
Last active January 4, 2021 09:35 — forked from cgrand/kein.sh
Launch a plain clojure repl according to project.clj without leiningen (most of the time)
#!/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
@miner
miner / bowling.clj
Last active January 4, 2021 09:35
Bowling Kata in Clojure
(ns miner.bowling)
;; http://codingdojo.org/cgi-bin/index.pl?KataBowling
;; https://www.javacodegeeks.com/2016/05/bowling-kata-clojure-f-scala.html
;; game is a string, encoding balls rolled
;; X for strike
;; / for spare
;; - for a miss or gutter ball
;; 1-9 for that many pins
(ns miner.dijkstra-primes)
;; ----------------------------------------------------------------------
;; http://heinrichhartmann.com/2016/04/03/Dijkstra's-Prime-Number-Algorithm.html
;; https://github.com/HeinrichHartmann/DijkstraPrimes/blob/master/Primes.lua
;; Converted to Clojure by SEM. Note that there are lots of shadowing and recursive calls in
;; the Clojure code to avoid the mutation in the original code. The Clojure loops are a bit
;; ugly. Not sure if this is the best way to do things. However, the performance is pretty
;; good.

Keybase proof

I hereby claim:

  • I am miner on github.
  • I am miner (https://keybase.io/miner) on keybase.
  • I have a public key whose fingerprint is DB15 4E49 B5BD BE5A 10B4 4437 6A9B 8B0A 4D6A 8900

To claim this, I am signing this object: