Skip to content

Instantly share code, notes, and snippets.

@bChiquet
bChiquet / .hs
Last active October 31, 2016 10:26
--Haskell as OO code
data Card = Card Rank Suit -- my object data
deriving (Eq, Show) -- The "Card" objects inherits Eq, Show from its subcomponents (Eq = equals, Show = toString)
instance Ord Card where -- I say Card implements the interface Ord
compare (Card rank1 _) (Card rank2 _) = compare rank1 rank2 -- Ord has the compare method so I implement it for Card
main = do
hspec $ do
describe "thisYearCoef" $ do
it "starts at 100" $ do
thisYearCoef New `shouldBe` 100
it "decreases by 5percent from previous year without accident" $ do
thisYearCoef (Existing 100) `shouldBe` 95
thisYearCoef (Existing 95) `shouldBe` 90
thisYearCoef (Existing 80) `shouldBe` 76
@bChiquet
bChiquet / noIfFizBuz.py
Created June 17, 2016 17:06
Maybe slightly overengineered ?
from fractions import gcd
import unittest
from itertools import combinations
baseMods=[(3, 'fizz'),
(5, 'buzz'),
(7, 'foo')]
mods = []