Skip to content

Instantly share code, notes, and snippets.

View msgodf's full-sized avatar

Mark Godfrey msgodf

View GitHub Profile
(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 / 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):
@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 / 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 / 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 / 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 / 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 / dijkstra-core.clj
Created May 30, 2012 07:28 — forked from mjg123/dijkstra-core.clj
Brisfunctional dojo code implementing dijkstra's algorithm 29-05-2012
(ns dijkstra.core)
(def initial-node {:score Integer/MAX_VALUE :route [] :dead? false})
(defn make-initial-state [edges start-node]
(-> (zipmap (keys edges) (repeat initial-node))
(assoc-in [start-node :score] 0)
(assoc-in [start-node :route] [start-node])))
(defn live-nodes [state]
@msgodf
msgodf / color_maven.sh
Created January 4, 2012 15:46
Colour Maven output
# Modified from http://repo.or.cz/w/anomen-overlay.git/tree/HEAD:/dev-java/maven-color
color_maven() {
local BOLD=`tput bold`
local TEXT_RED=`tput setaf 1`
local TEXT_GREEN=`tput setaf 2`
local TEXT_YELLOW=`tput setaf 3`
local RESET_FORMATTING=`tput sgr0`
$MAVEN_HOME/bin/mvn $@ | sed -e "s/\(\[INFO\]\ \-\-\-\ .*\)/${TEXT_BLUE}\1${RESET_FORMATTING}/g" \
-e "s/\(\[INFO\]\ \[.*\)/${RESET_FORMATTING}\1${RESET_FORMATTING}/g" \
-e "s/\(\[INFO\]\ \)\(BUILD SUCCESS\)/\1${TEXT_GREEN}\2${RESET_FORMATTING}/g" \
@msgodf
msgodf / ABCD.js
Created June 1, 2011 09:56
Code to run arbitrary JavaScript code as a string, using only the characters []$=()-+~""!_
[][$___=(($=(({}+"")))[$__=-~-~-~-~-~[]]+$[-~[]]+(""[+[]]+"")[-~[]]+(![]+"")[-~-~-~[]]+(($_=(!""+"")))[+[]]+$_[-~[]]+$_[-~-~[]]+$[$__]+$_[+[]]+$[-~[]]+$_[-~[]])][$___](($$=($_____=(!""+"")[-~[]]+(!""+"")[-~-~-~[]]+(!""+"")[+[]]+(!""+"")[-~-~[]]+(!""+"")[-~[]]+(""[+[]]+"")[-~[]]
)+"[][$___][$___]('"+$_____+"\"\\"+(""[+[]]+"")[+[]]
+(+[])+(+[]))+($$$=""+(-~-~-~-~[])+(-~[]))+($$$$="\"')()"))()+[][$___][$___]($$+($$$=-~$$$)+$$$$)()+[][$___][$___]($$+($$$=-~$$$)+$$$$)()+[][$___][$___]($$+($$$=-~$$$)+$$$$)()