View assert.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package assert | |
import ( | |
"reflect" | |
"testing" | |
) | |
// That allows assertions as in: assert.That(t, actual).Equals(expected) | |
func That(t *testing.T, actual interface{}) *assertion { |
View bowling-test.rkt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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))) |
View life.clj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns kata.life) | |
(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)) |
View ttt.clj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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)))) |
View framed-bowling.clj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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)])) |
View minimal-bowling.clj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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] | |
(cond | |
(empty? rolls) [] |
View bowling.clj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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))) |
View template.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package templates | |
import ( | |
"bytes" | |
"fmt" | |
"io" | |
"text/template" | |
) | |
func ParseAndExecute(format string, args ...interface{}) string { |
View bowling.rkt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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) |
NewerOlder