Re: Just quick review - "idiomaticy" check (Selection sort)

2016-10-10 Thread Mark Engelberg
Doesn't seem fair to use a sort algorithm in the implementation of selection sort. Besides, sort is an n*logn operation, so you don't want to (first (sort-by second ...)) anyway. Instead, choose (apply min-key second ...). Only catch is you need to make sure you don't pass an empty list, or it w

Re: Just quick review - "idiomaticy" check (Selection sort)

2016-10-10 Thread Steve Miner
> On Oct 10, 2016, at 6:50 AM, Rastko Soskic wrote: > > I am specially interested in better way for processing input which shrinks > after each step. Vectors have some nice properties if your action is mostly at the end. The peek and pop functions are useful for “shrinking” a vector. Also,

Re: Just quick review - "idiomaticy" check (Selection sort)

2016-10-10 Thread Rastko Soskic
Yeah you are right, it is simpler, I just wanted to avoid usage of any sort* function, I've probably gone too far :) *split-at* is cool reminder :) totally forgot about it :) Thanks! On Monday, October 10, 2016 at 3:33:16 PM UTC+2, Moe Aboulkheir wrote: > > Here's an example w/ iterate & a simpl

Re: Just quick review - "idiomaticy" check (Selection sort)

2016-10-10 Thread Moe Aboulkheir
Here's an example w/ iterate & a simpler 'smallest': (defn- smallest [xs] (->> xs (map-indexed vector) (sort-by second) first)) (defn selection-sort [s] (->> (iterate (fn [[acc xs]] (let [[i x] (smallest xs) [l r] (split-at i xs)] [(conj acc x) (c

Just quick review - "idiomaticy" check (Selection sort)

2016-10-10 Thread Rastko Soskic
Hi, I thought perhaps asking on IRC instead here - but chose here anyway :) I am doing just some exercises in scope of various algorithms, data structures etc. Currently, in scope is *selection sort*. I came up of this implementation in Clojure (original examples are in Python and Ruby where in