Skip to content

Instantly share code, notes, and snippets.

@lf94
Created September 17, 2014 18:37
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 lf94/0b2490eda7b64b7aa17f to your computer and use it in GitHub Desktop.
Save lf94/0b2490eda7b64b7aa17f to your computer and use it in GitHub Desktop.
Big John's Beef Jerky Calculator
import System.Environment(getArgs)
import Graphics.Rendering.Chart
import Data.Colour
import Data.Colour.Names
import Data.Default.Class
import Graphics.Rendering.Chart.Backend.Diagrams
import Graphics.Rendering.Chart.Axis.Floating
import Control.Lens
lifetime_discount = 0.05
loyalty_discount = [0.00, 0.03, 0.05, 0.07]
bjbj_trunc :: Rational -> Rational
bjbj_trunc x = fromIntegral(floor (x * 10)) / 10
bjbj_other_discount :: Rational -> Rational -> Rational
bjbj_other_discount x d = bjbj_trunc (x * d)
bjbj_discount :: Rational -> Rational -> Rational
bjbj_discount x d = x - (x * d)
bjbj_discount_amount :: Rational -> Rational
bjbj_discount_amount x
| x < 50.00 = 0
| x < 129.00 = 0.25
| x < 275.00 = 0.30
| x < 718.00 = 0.35
| x < 1724.00 = 0.37
| x < 3000.00 = 0.40
| x >= 3000.00 = 0.44
bjbj :: Rational -> Rational -> Double
bjbj x loyalty = fromRational(discounted_price - ((bjbj_other_discount discounted_price lifetime_discount) + (bjbj_other_discount discounted_price loyalty)))
where
discounted_price = bjbj_discount x (bjbj_discount_amount x)
chart = toRenderable layout
where
loyalty :: [PlotLines Double Double]
loyalty = [(plot_lines_values .~ [[ (fromRational x, bjbj x (loyalty_discount !! 0)) | x <- [0.0, 1.0..3100.0] ]]
$ plot_lines_style . line_color .~ opaque blue
$ plot_lines_title .~ "0% Loyalty Rewards"
$ def), (plot_lines_values .~ [[ (fromRational x, bjbj x (loyalty_discount !! 1)) | x <- [0.0, 1.0..3100.0] ]]
$ plot_lines_style . line_color .~ opaque red
$ plot_lines_title .~ "0.03% Loyalty Rewards"
$ def), (plot_lines_values .~ [[ (fromRational x, bjbj x (loyalty_discount !! 2)) | x <- [0.0, 1.0..3100.0] ]]
$ plot_lines_style . line_color .~ opaque green
$ plot_lines_title .~ "0.05% Loyalty Rewards"
$ def), (plot_lines_values .~ [[ (fromRational x, bjbj x (loyalty_discount !! 3)) | x <- [0.0, 1.0..3100.0] ]]
$ plot_lines_style . line_color .~ opaque purple
$ plot_lines_title .~ "0.07% Loyalty Rewards"
$ def)]
layout = layout_title .~ "Big John's Beef Jerky Bulk Pricing (with Lifetime Loyalty Discount (5%))"
$ layout_plots .~ fmap toPlot loyalty
$ def
main = renderableToSVGFile chart 800.0 600.0 "bigjohnsbeefjerky_optimal.svg"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment