User Tools

Site Tools


study:algorithms:greedy

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
study:algorithms:greedy [2013/05/18 02:16]
djey9538
study:algorithms:greedy [2019/02/04 14:26] (current)
Line 175: Line 175:
       return ret;       return ret;
   }   }
 +</​code>​
 +
 +clojure
 +<code clojure>
 +(defn heat [dosirocks]
 +  (let [begin-eat (atom 0)
 +        sorted (reverse (sort-by second dosirocks))
 +        ret (for [[e m] sorted]
 +              (do
 +                (swap! begin-eat + e)
 +                (+ @begin-eat m)))]
 +    (apply max ret)))
 +
 +(= (heat [[2 2] [2 2] [2 2]]) 8)
 +(= (heat [[1 2] [2 2] [3 1]]) 7)
 </​code>​ </​code>​
  
study/algorithms/greedy.txt · Last modified: 2019/02/04 14:26 (external edit)