Skip to content

Instantly share code, notes, and snippets.

@RyanGough
RyanGough / core-test.clj
Created October 13, 2015 21:51
Initial stab at a very basic implmentation of the lift / elevator kata in clojure.
(ns lift-kata.core-test
(:require [clojure.test :refer :all]
[lift-kata.core :refer :all]))
(deftest open-door-on-requested-floor
(testing "Should open the doors if only request is current floor."
(is (= {:doors :open :floor 0 :requests []}
(lift-kata.core/next-lift-state {:doors :closed :floor 0 :requests[]},
[0])))))
@RyanGough
RyanGough / core-test.clj
Created September 10, 2015 21:57
checkout kata in clojure
(ns checkout.core-test
(:require [clojure.test :refer :all]
[checkout.core :refer :all]))
(deftest single-item
(testing "scannng a single A item gives price 50"
(is (= 50 (scan ["A"])))))
(deftest different-item
(testing "scannng a single B item gives price 30"
@RyanGough
RyanGough / jobsort.erl
Last active August 29, 2015 14:20
ordered jobs kata in erlang
-module (jobsort).
-export ([sort/1,test/0]).
sort(JobSpec) ->
EdgesAndVertices = get_edges_and_vertices(string:tokens(JobSpec, "\r\n"), [], []),
Graph = build_graph(EdgesAndVertices),
case digraph_utils:is_acyclic(Graph) of
true ->
lists:reverse(digraph_utils:topsort(Graph));

Keybase proof

I hereby claim:

  • I am RyanGough on github.
  • I am ryanwgough (https://keybase.io/ryanwgough) on keybase.
  • I have a public key whose fingerprint is 76D7 9BF6 4DCC 47E5 FF68 8650 1246 5F3C 877B EED6

To claim this, I am signing this object:

@RyanGough
RyanGough / 121.js
Created October 5, 2013 00:51
convert array of numbers into string with ranges i.e [1,2,3,4,6,8,9] => "1-4,6,8-9"
function play (a) {
return a.reduce(function(c,t,i) {
if (t-a[i-1]<2) {
c=(c+'').replace(/-.$/, '')
c+='-'
} else c+=','
return c+t
})
}