I was a bit curious regarding the math with the anvil, so as an exercise, threw together an anvil cost calculator (optimizer). You can lay out all your books ahead of time and the code tries combinations in every order to return the cheapest one. Check out the presets to get an idea of how to get started. Feel free to give me feedback or create feature requests on the github page.[/p]
Anvil Cost Calculator