Problem #43

49 views
Skip to first unread message

Gabi Munteanu

unread,
Jul 2, 2017, 2:41:46 PM7/2/17
to 4Clojure
Hi,
 
I tried this solution for reverse interleave problem 43:

(fn revinter [x n]

  (partition (/ (count x) n) (/ (count x) n) (sort-by #(mod (+ %1 (- n 1)) n) x)))


However the second test with (range 9) gives me an error:

Don't know how to create ISeq from: clojure.lang.Var$Unbound

What can I do about it

Leif

unread,
Jul 3, 2017, 7:40:24 PM7/3/17
to 4Clojure
Hi, Gabi.

I can't address your original question, since I don't get that error, but I have some suggestions:

Your code assumes that the elements of the input sequences are numbers in order.  All of the test cases are like that, but that's just an oversight: the function should work on any sequence.  Here is a test case for you to use:

(= (__ [:a :b :c :d :e :f] 3)  '((:a :d) (:b :e) (:c :f)))

In fact, your code assumes the elements are numbers, in order, starting from 1.  It gives the wrong answer for test cases 2 and 3.  I do think your approach could work, if you can somehow use the index of the element rather than the element itself.  But, as a hint, there are solutions that don't explicitly look at either the element or its index.

Good luck,
Leif
Reply all
Reply to author
Forward
0 new messages