This file contains hidden or 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 game; | |
public interface Cell { | |
public Cells getNeighbors(); | |
} |
This file contains hidden or 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
var fizzbuzz = function (numbers) { | |
var fizzbuzz_one = function (number) { | |
var res = ""; | |
if (number % 3 == 0) | |
res += "Fizz"; | |
if (number % 5 == 0) | |
res += "Buzz"; |
This file contains hidden or 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
var makeSubstitution = function (divisor, substitute) { | |
return function substituteNumberBy(acc, number) { | |
if (number % divisor == 0) { | |
acc += substitute; | |
} | |
return acc; | |
}; | |
}; | |
var substitute = function (numbers, substitutions) { |
This file contains hidden or 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
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(""); |
This file contains hidden or 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
var makeSubstitution = function (divisor, substitute) { | |
return function substituteNumberBy(acc, number) { | |
if (number % divisor == 0) { | |
acc += substitute; | |
} | |
return acc; | |
}; | |
}; | |
var substitute = function (numbers, substitutions) { |
This file contains hidden or 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
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); | |
}); | |
This file contains hidden or 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
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); | |
}); | |
This file contains hidden or 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
var rules = (function () { | |
function hasThreeNeighbors(numberOfNeighbors) { | |
return numberOfNeighbors == 3; | |
} | |
function hasTwoNeighbors(numberOfNeighbors) { | |
return numberOfNeighbors == 2; | |
} | |
return { |
This file contains hidden or 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
type gesture = | |
| Paper | |
| Rock | |
| Scissors | |
type result = | |
| Win of gesture * gesture | |
| Lose of gesture * gesture | |
| Tie of gesture |
This file contains hidden or 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 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") |