Skip to content

Instantly share code, notes, and snippets.


Michael Whatcott mdwhatcott

View GitHub Profile
mdwhatcott / assert.go
Last active Jun 22, 2022
The tiniest testing library
View assert.go
package assert
import (
// That allows assertions as in: assert.That(t, actual).Equals(expected)
func That(t *testing.T, actual interface{}) *assertion {
mdwhatcott / bowling-test.rkt
Last active Apr 5, 2022
Bowling Game Kata (in Racket)
View bowling-test.rkt
#lang racket
(require rackunit)
(require "bowling.rkt")
(define (roll-many times roll)
(for/list ([i times]) roll))
(test-equal? "Gutter Game" 0 (score (roll-many 20 0)))
(test-equal? "All Ones" 20 (score (roll-many 20 1)))
mdwhatcott / life.clj
Last active Sep 13, 2021
The Game of Life Kata
View life.clj
(defn neighbors-of [[x y]]
(for [Y (range (dec y) (+ 2 y))
X (range (dec x) (+ 2 x))
:when (not= [x y] [X Y])] [X Y]))
(defn count-active-neighbors [cell grid]
(->> cell neighbors-of set (filter grid) count))
mdwhatcott / ttt.clj
Created Aug 24, 2021
Tic-Tac-Toe Grid GUI Prototype (clojure, quil)
View ttt.clj
(ns hello-quil.grid
(:require [quil.core :as q]
[quil.middleware :as m]))
(defn hovering? [{:keys [x y width mark] :as cell}]
(let [x2 (+ x width)
y2 (+ y width)
mx (q/mouse-x)
my (q/mouse-y)]
(and (nil? mark)
View prime-factors.clj
(ns factors.core-spec
(:require [speclj.core :refer :all]
[factors.core :refer :all]))
(defn factors-of [n]
(loop [n n, d 2, fs []]
(cond (= n 1) fs
(zero? (mod n d)) (recur (/ n d) d (conj fs d))
:else (recur n (inc d) fs))))
mdwhatcott / framed-bowling.clj
Last active Aug 12, 2021
View framed-bowling.clj
(ns bowling.core-spec
(:require [speclj.core :refer :all]))
(defn is-strike? [[first & _]] (= 10 first))
(defn is-spare? [[first second & _]] (= 10 (+ first second)))
(defn split-frame [rolls]
(cond (is-strike? rolls) [(take 3 rolls) (rest rolls)]
(is-spare? rolls) [(take 3 rolls) (drop 2 rolls)]
:else [(take 2 rolls) (drop 2 rolls)]))
mdwhatcott / minimal-bowling.clj
Last active Aug 7, 2021
View minimal-bowling.clj
(ns bowling.core-spec
(:require [speclj.core :refer :all]))
(defn is-strike? [rolls] (= 10 (first rolls)))
(defn is-spare? [rolls] (= 10 (apply + (take 2 rolls))))
(defn ->frames [rolls]
(empty? rolls) []
View bowling.clj
(ns bowling.core-spec
(:require [speclj.core :refer :all]))
(def all-pins 10)
(def frames-per-game 10)
(defn game-over [frame] (= frame frames-per-game))
(defn strike-score [rolls] (+ all-pins (nth rolls 1) (nth rolls 2)))
(defn spare-score [rolls] (+ all-pins (nth rolls 2)))
(defn frame-score [rolls] (+ (first rolls) (second rolls)))
(defn is-strike [rolls] (= all-pins (first rolls)))
mdwhatcott / template.go
Created Apr 2, 2021
fmt.Sprintf -> template.Execute
View template.go
package templates
import (
func ParseAndExecute(format string, args ...interface{}) string {
mdwhatcott / bowling.rkt
Created Jan 16, 2021
The 'Bowling Game' Kata in Racket
View bowling.rkt
#lang racket
(define LAST-FRAME 10)
(define ALL-PINS 10)
(define (is-spare? rolls) (= ALL-PINS (+ (first rolls) (second rolls))))
(define (is-strike? rolls) (= ALL-PINS (first rolls)))
(define (score-frame frame score rolls)
(score-frames (add1 frame)