Created
October 11, 2010 20:31
-
-
Save abrenk/621166 to your computer and use it in GitHub Desktop.
This file contains 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
(loop [curr 53 | |
dir true | |
jobs #{98 183 37 122 14 124 65 67 199} | |
sum 0] | |
(let [f (condp = dir | |
false (partial < curr) | |
true (partial > curr)) | |
s (condp = dir | |
false sort | |
true (comp reverse sort)) | |
l (condp = dir | |
false 199 | |
true 0) | |
sect (first (s (filter f jobs))) | |
dist (if (nil? sect) | |
(Math/abs (- curr l)) | |
(Math/abs (- curr sect)))] | |
(if (empty? jobs) | |
sum | |
(recur | |
(if ( nil? sect) l sect) | |
(if ( nil? sect) (not dir) dir) | |
(disj jobs sect) | |
(+ sum dist))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment