-
-
Save dozed/f12791c9ed15fa6e76b50beffd8ad77c to your computer and use it in GitHub Desktop.
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
type Cost = Int | |
data RobotCost = RobotCost { | |
oreCost :: Cost, | |
clayCost :: Cost, | |
obsidianCost :: Cost | |
} deriving (Eq, Show) | |
instance Semigroup RobotCost where | |
(<>) rc1 rc2 = | |
RobotCost { | |
oreCost = oreCost rc1 + oreCost rc2, | |
clayCost = clayCost rc1 + clayCost rc2, | |
obsidianCost = obsidianCost rc1 + obsidianCost rc2 | |
} | |
stimes n rc = | |
RobotCost { | |
oreCost = oreCost rc * fromIntegral n, | |
clayCost = clayCost rc * fromIntegral n, | |
obsidianCost = obsidianCost rc * fromIntegral n | |
} | |
instance Monoid RobotCost where | |
mempty = RobotCost { oreCost = 0, clayCost = 0, obsidianCost = 0 } | |
mappend = (<>) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment