Skip to content

Instantly share code, notes, and snippets.

View msgodf's full-sized avatar

Mark Godfrey msgodf

View GitHub Profile
@msgodf
msgodf / dijkstra-core.clj
Created May 30, 2012 07:32 — forked from tcoupland/dijkstra-core.clj
Brisfunctional dojo code implementing dijkstra's algorithm 29-05-2012
(ns dijkstra.core)
(def edges {:A {:F 14 :C 9 :B 7}
:B {:A 7 :C 10 :D 15}
:C {:A 9 :B 10 :D 11 :F 2}
:D {:B 15 :C 11 :E 6}
:E {:D 6 :F 9}
:F {:A 14 :C 2 :E 9}})
(def inf Integer/MAX_VALUE)
@msgodf
msgodf / gist:2982481
Created June 24, 2012 08:40
Functions to generate and print the Mandelbrot set
(defn vec-abs
[[x y]]
(+ (* x x)
(* y y)))
(defn vec-add
[x y]
(map + x y))
(defn vec-sq
@msgodf
msgodf / gist:2994144
Created June 26, 2012 07:36
Clojure functions _can_ be made to take more than 20 parameters.
(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))
@msgodf
msgodf / alerting.md
Created October 13, 2015 09:58
"My Philosophy on Alerting" - Rob Ewaschuk

My Philosophy on Alerting based my observations while I was a Site Reliability Engineer at Google

Author: Rob Ewaschuk rob@infinitepigeons.org

Introduction Vernacular Monitor for your users Cause-based alerts are bad (but sometimes necessary) Alerting from the spout (or beyond!)

@msgodf
msgodf / gist:4251107
Created December 10, 2012 15:06
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]
(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)))
@msgodf
msgodf / radiation_search.clj
Created December 11, 2012 08:29
Clojure solution to to "Radiation Search" problem on check.io
(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)))))))))
@msgodf
msgodf / radiation_search.py
Last active December 9, 2015 23:29
Python solution to the "Radiation Search" problem on check.io
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):
(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]
@msgodf
msgodf / brisfunctional-ocr-kata-failures
Created April 10, 2013 08:03
Several attempts to get a sweet solution to getting digit parcel part of Brian Marick's Brisfunctional talk.
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)