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
> 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,
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
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
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