Last active
December 28, 2015 12:33
-
-
Save desbo/6f762878cc183ee89e1b to your computer and use it in GitHub Desktop.
codewars
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; 559e3224324a2b6e66000046 | |
(defn cart [n] | |
(let [n (+ n 1)] | |
(for [x (range 1 n) y (range 1 n)] [x y]))) | |
(defn xf [f] (map (fn [[x y]] (f x y)))) | |
(defn sumin [n] | |
(transduce (xf min) + (cart n))) | |
(defn sumax [n] | |
(transduce (xf max) + (cart n))) | |
(defn sumsum [n] | |
(+ (sumin n) (sumax n))) | |
;; 562f91ff6a8b77dfe900006e | |
(defn movie [card ticket perc] | |
(loop [visits 1 | |
last-paid 0] | |
(let [system-a (* ticket visits) | |
system-b (+ last-paid (* ticket (reduce * (repeat visits perc))))] | |
(if (< (Math/ceil (+ card system-b)) system-a) | |
visits | |
(recur (inc visits) system-b))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment