Skip to content

Instantly share code, notes, and snippets.

@voidlily
Last active December 30, 2015 07:39
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 voidlily/7797385 to your computer and use it in GitHub Desktop.
Save voidlily/7797385 to your computer and use it in GitHub Desktop.
(defn rent [initial year]
"Calculates the rent for a given year. Assumes 1.9% increase yearly based on SF rent control."
(* initial (Math/pow 1.019 year)))
(defn rent-seq [price]
"Generates a lazy infinite sequence of rent increases based on a given base price."
(map #(rent price %) (iterate inc 0)))
; Get the projected rent increases for living at a place for 10 years
(->> (rent-seq 2000) (take 10) (map #(format "%.2f" %)))
("2000.00" "2038.00" "2076.72" "2116.18" "2156.39" "2197.36" "2239.11" "2281.65" "2325.00" "2369.18")
; How much will it cost yearly?
(->> (rent-seq 2000) (map #(* 12 %)) (take 10) (map #(format "%.2f" %)))
("24000.00" "24456.00" "24920.66" "25394.16" "25876.65" "26368.30" "26869.30" "27379.82" "27900.03" "28430.13")
; How much will I spend on rent in total for the next 10 years?
(->> (rent-seq 2000) (map #(* 12 %)) (take 10) (reduce +) (format "%.2f"))
"261595.05"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment