Skip to content

Instantly share code, notes, and snippets.

@trikitrok
trikitrok / Cell.java
Created February 2, 2014 01:41
Cell interface
package game;
public interface Cell {
public Cells getNeighbors();
}
var fizzbuzz = function (numbers) {
var fizzbuzz_one = function (number) {
var res = "";
if (number % 3 == 0)
res += "Fizz";
if (number % 5 == 0)
res += "Buzz";
var makeSubstitution = function (divisor, substitute) {
return function substituteNumberBy(acc, number) {
if (number % divisor == 0) {
acc += substitute;
}
return acc;
};
};
var substitute = function (numbers, substitutions) {
@trikitrok
trikitrok / fizzbuzz2Tests.js
Last active June 30, 2024 14:32
fizzBuzz generalization spec
describe("FizzBuzz", function () {
var fizzBuzzSubstitutionRules;
beforeEach(function () {
fizzBuzzSubstitutionRules = [makeSubstitution(3, "Fizz"),
makeSubstitution(5, "Buzz")];
});
it("returns empty string for an empty array", function () {
expect(substitute([], fizzBuzzSubstitutionRules)).toBe("");
@trikitrok
trikitrok / fizzbuzz3.js
Created February 6, 2014 07:36
Refactored substitute using Array.map and Array.join
var makeSubstitution = function (divisor, substitute) {
return function substituteNumberBy(acc, number) {
if (number % divisor == 0) {
acc += substitute;
}
return acc;
};
};
var substitute = function (numbers, substitutions) {
@trikitrok
trikitrok / conwaysRulesTests.js
Last active June 30, 2024 14:32
Conway's rules tests better names
describe("rules", function() {
describe("rule to go on living", function() {
it("does't go on living because of overpopulation", function() {
expect(rules.goesOnLivingWith(4)).toBe(false);
});
it("does't go on living because of underpopulation", function() {
expect(rules.goesOnLivingWith(1)).toBe(false);
});
@trikitrok
trikitrok / conwaysRulesTestsInitial.js
Last active June 30, 2024 14:32
Conway's rules tests initial names
describe("rules", function() {
describe("rule to go on living", function() {
it("dies with more than 3 neighbors", function() {
expect(rules.goesOnLivingWith(4)).toBe(false);
});
it("dies with less than 2 neighbors", function() {
expect(rules.goesOnLivingWith(1)).toBe(false);
});
@trikitrok
trikitrok / conwaysRules.js
Created February 8, 2014 20:43
Conways rules js code
var rules = (function () {
function hasThreeNeighbors(numberOfNeighbors) {
return numberOfNeighbors == 3;
}
function hasTwoNeighbors(numberOfNeighbors) {
return numberOfNeighbors == 2;
}
return {
@trikitrok
trikitrok / RockPaperScissorsGame.ml
Last active June 30, 2024 14:32
Rock, Paper, Scissors game in OCaml
type gesture =
| Paper
| Rock
| Scissors
type result =
| Win of gesture * gesture
| Lose of gesture * gesture
| Tie of gesture
@trikitrok
trikitrok / rockpaperscissors.clj
Created February 12, 2014 10:05
Rock, Paper, Scissors using Clojure multimethods
(ns rockpaperscissors.core)
(derive ::Rock ::Gesture)
(derive ::Paper ::Gesture)
(derive ::Scissors ::Gesture)
(defmulti hand (fn [x y] [(:Gesture x) (:Gesture y)]))
(defmethod hand [:Rock :Paper] [_ _]
"Second player's Paper beats first player's Rock")