Skip to content

Instantly share code, notes, and snippets.

@abrenk
Created October 11, 2010 20:31
Show Gist options
  • Save abrenk/621166 to your computer and use it in GitHub Desktop.
Save abrenk/621166 to your computer and use it in GitHub Desktop.
(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