Skip to content

Instantly share code, notes, and snippets.

@Heimdell
Last active October 12, 2015 01:58
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 Heimdell/3954026 to your computer and use it in GitHub Desktop.
Save Heimdell/3954026 to your computer and use it in GitHub Desktop.
Minecraft resource calculator
module Mine where
import Data.Ratio
import Control.Monad (join)
import Data.List
import qualified Data.Map as Map
import Data.Map (Map)
second = one "second"
gold = one "gold"
iron = one "iron"
coal = one "coal"
cobble = one "cobblestone"
redstone = one "redstone"
wood = one "wood"
glowstone = one "glowstone"
eu = one "eu"
diamond = one "diamond"
diamond_pickaxe = nothing
.+. diamond .*. 3
.+. stick .*. 2
stone = nothing
.+. cobble
-- .+. second .*. 10
.+. coal ./. 8
stone_brick = stone .*. 4 `returns` 4
block_dug = nothing
.+. diamond_pickaxe ./. 1500
.+. second ./. 4
plank = wood `returns` 4
stick = plank .*. 2 `returns` 4
fence = stick .*. 6 `returns` 2
golden_rails = nothing
.+. gold .*. 6
.+. redstone
.+. stick
`returns` 6
rails = nothing
.+. iron .*. 6
.+. stick
`returns` 16
button = stone .*. 2
red_torch = redstone .+. stick
torch = coal .+. stick `returns` 4
lever = cobble .+. stick
station = nothing
.+. glowstone .*. 1
.+. rails .*. 8
.+. golden_rails .*. 8
.+. button .*. 4
.+. lever .*. 4
.+. redstone .*. 4
track len =
let slice = nothing
.+. stone_brick .*. (25 - 9)
.+. block_dug .*. 25
.+. rails .*. (26 / 27)
.+. golden_rails .*. (1 / 27)
.+. red_torch .*. (1 / 27)
in slice .*. len
hell_track len = track (len / 8)
---- 8< HEAVY MACHINERY DOWN THERE ----
g |> f = f . g
x $> f = f x
data Cost
= Cost { cost :: Map String (Ratio Int) }
data As = Cost `As` Cost
deriving Show
as = As
instance Show Cost where
show = cost
|> Map.toList
|> map toString
|> intercalate ", "
where
toString (res, c) = join [show (ceiling c), " ", res]
one n = Map.fromList [(n, 1)] $> Cost
nothing = Map.empty $> Cost
infixr 6 .+.
infixr 7 ./., .*.
infix 5 `returns`
Cost list .+. Cost other =
Cost $ Map.unionWith (+) list other
Cost list .*. n =
Cost $ Map.map (* n) list
cost ./. n = cost .*. (1 / n)
returns = (./.)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment