Arc Forumnew | comments | leaders | submitlogin
3 points by thaddeus 4650 days ago | link | parent

Somehow I doubt this would be any better + I haven't even considered performance,.. but just for fun:

  (def sort-by-commonest (xs)
    ((afn (rx rs)
       (if (empty rx) rs
           (let (x n)(commonest rx)
             (self (rem x rx)(join rs (n-of n x))))))
        xs nil))

  arc> (sort-by-commonest '(1 3 3 4 4 5 4))
  (4 4 4 3 3 5 1)
  
Generally speaking, I avoid iterative updates to tables as I often find it ends up being less efficient than consing a collection together. Also,... this is not a stable sort as yours is, but maybe I can get some points for creativity?


1 point by akkartik 4650 days ago | link

Point granted :)

-----