Minecraft has gotten to be a very popular game. No doubt many reading this have played it themselves or watched someone else. In Minecraft, collected ore must be smelted in a furnace to change the resource into a usable form.
Each ingot takes 11 seconds to produce. Steve has the following fuel options to add to the furnace:
Buckets of lava, each lasts 800 seconds
Blaze rod, each lasts 120 seconds
Coals, each lasts 80 seconds
Blocks of Wood, each lasts 15 seconds
Sticks, each lasts 1 second*
Write a function that calculates the minimum amount of fuel needed to produce a certain number of iron ingots.
Ruby: {:lava => 2, :blaze_rod => 1, :coal => 1, :wood => 0, :stick => 0}
JavaScript: {lava: 2, blazeRod: 1, coal: 1, wood: 0, stick: 0}
Good luck!~
Today's challenge comes from arwengu on CodeWars. Thank you to CodeWars, who has licensed redistribution of this challenge under the 2-Clause BSD License!
Want to propose a challenge idea for a future post? Email yo+challenge@dev.to with your suggestions!
Top comments (8)
Time to Go smelting!
ingots.go
ingots_test.go
My solution in JavaScript:
I think I interpreted this correctly (though "minimum number" could mean a few different things here...)
Here's my solution using javascript's
reduce
:And you can watch me solve it here! youtu.be/wtA4CKbZipA
Python
The challenge was a little bit ambiguous about the requirement. If I understand correctly, is asking about at least how many resources of each fuel you require to try to smelt iron ingots.
With this, I wrote the following solution in JavaScript
I'm not sure if I'm correctly interpreting the problem, but:
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 withMaybe
s when looking up items from the map. Any advice or reccomendations would be appreciated.link to codewars?