DEV Community

Discussion on: Daily Challenge #58 - Smelting Iron Ingots

Collapse
 
craigmc08 profile image
Craig McIlwrath

I'm not sure if I'm correctly interpreting the problem, but:

data Fuels a = Fuels { lava :: a
                   , blazeRod :: a
                   , coal :: a
                   , wood :: a
                   , stick :: a
                   } deriving (Show, Eq)

defFuels :: (Integral a) => Fuels a
defFuels = Fuels 0 0 0 0 0

minFuel :: (Integral a) => a -> Fuels a
minFuel items = defFuels{lava = ceiling $ fromIntegral items * 11 / 800}

The minimum amount of fuel to cook n items will always be only lava buckets...

My other interpretation was the amount of fuel to get the exact correct smelting time. I did work on a solution for that, but it felt very verbose with a lot of repeated code to work with my Fuels type. I'm pretty new to Haskell, so I'm not sure if this is the best thing to use in this situation. I did think about using a map, but then I would have to deal with Maybes when looking up items from the map. Any advice or reccomendations would be appreciated.