Skip to content

Instantly share code, notes, and snippets.

@dozed
Last active January 28, 2023 20:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dozed/f12791c9ed15fa6e76b50beffd8ad77c to your computer and use it in GitHub Desktop.
Save dozed/f12791c9ed15fa6e76b50beffd8ad77c to your computer and use it in GitHub Desktop.
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