Haskell solution. The last argument of the function is the base damage. I'm also changing the function to accept an ADT Type type instead of strings for the Pokémon type.
data Type = Grass | Fire | Water | Electric deriving (Eq) effect :: Type -> Type -> Double effect Fire Grass = 2 effect Water Fire = 2 effect Fire Electric = 1 effect Grass Water = 2 effect Electric Water = 2 effect Grass Electric = 1 effect a b | a == b = 1 | otherwise = recip $ effect b a totalDamage :: Type -> Type -> Double -> Double -> Double -> Double totalDamage t1 t2 att def = (*) $ att / def * effect t1 t2
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Haskell solution. The last argument of the function is the base damage. I'm also changing the function to accept an ADT Type type instead of strings for the Pokémon type.