Avoid the fall of your city
Your city is modeled by several gauges :
- gold
- wheat
from fractions import gcd | |
import unittest | |
from itertools import combinations | |
baseMods=[(3, 'fizz'), | |
(5, 'buzz'), | |
(7, 'foo')] | |
mods = [] |
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 | |
--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 |
import random | |
city = {"gold" : 5, | |
"food" : 5, | |
"health" : 5, | |
"civilians" : 5, | |
"army" : 5} | |
def hasFallen (city) : | |
def militaryPutsch(city): |
event_reaction_map = {} | |
def apply_events_triggered_by(event): | |
if event in event_reaction_map: | |
for reaction in event_reaction_map[event]: | |
reaction() | |
def react_to(event): |
event_reaction_map = {} | |
def apply_effects_of(event): | |
if event in event_reaction_map: | |
for reaction in event_reaction_map[event]: | |
reaction() | |
def react_to(event): |
from unittest import TestCase | |
class Anything: | |
def __eq__(self, other): | |
return True | |
def __ne__(self, other): | |
return False |
# Let's start with an easy challenge... Hundreds of visitors shop inside a shopping mall . | |
# The aim of this challenge is to determine how many people are present in the shopping mall | |
# at a given point in time. | |
# | |
# Data | |
# | |
# Input |
import Test.Hspec | |
main = hspec $ do | |
describe "fizbuzz" $ do | |
it "1 gives 1" $ do | |
fizzBuzz 1 `shouldBe` "1" | |
it "2 gives 2" $ do | |
fizzBuzz 2 `shouldBe` "2" | |
it "3 gives fizz" $ do | |
fizzBuzz 3 `shouldBe` "fizz" |