Guest User

Untitled

a guest
Sep 23rd, 2011
243
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. (defn partition-into [ fnc n seqinput ]
  2.     (let [ a (reverse (sort seqinput)) ]
  3.         (reduce (fn[ cubes  val ]
  4.             (let [ ordered-cubes (sort-by #(apply fnc val %1) cubes) ]
  5.                 (cons (conj (first ordered-cubes) val) (rest ordered-cubes))))
  6.                     (map vector (take n a)) (drop n a) )))
  7.  
  8.  
  9. (partition-into + 5  [ 1 2 34  54 12 23 5  2 3  1 2 12 11 12 32 67 ] )
  10.  
  11. ; gives ([32 12 5 1 1] [34 12 2 2] [23 12 11 3 2] [54] [67])
Advertisement
Add Comment
Please, Sign In to add comment