help for problem 33, replicate a sequence

115 views
Skip to first unread message

Ziad Mansouri

unread,
Feb 1, 2012, 9:46:09 PM2/1/12
to 4Clojure
http://www.4clojure.com/problem/31

I can make the first 3 unit tests pass but not the last two (because
of flatten). Any and all help is much appreciated.

Z.

Ted Naleid

unread,
Feb 1, 2012, 11:00:25 PM2/1/12
to 4clo...@googlegroups.com
Are you sure it's 31 you're talking about (Pack a Sequence)?

It only has 3 unit tests on it, not 5.

If it's 31 you're talking about I solved it with partition-by identity, which will group things based on whether they're the same thing:

#(partition-by identity %)

-Ted

Ziad Mansouri

unread,
Feb 2, 2012, 8:55:19 PM2/2/12
to 4Clojure
Oops, sorry about that. It's 33 as it says in the subject. URL:
http://www.4clojure.com/problem/33.

Ted Naleid

unread,
Feb 2, 2012, 9:03:38 PM2/2/12
to 4clo...@googlegroups.com
Oops, missed your title, just looked at the url.

Ok, I solved that one with mapcat & repeat:

(fn [s n] (mapcat #(repeat n %) s))

mapcat (http://clojuredocs.org/clojure_core/clojure.core/mapcat) is helpful for quite a few of the "Easy" level problems that I've figured out so far.

-Ted

Ziad Mansouri

unread,
Feb 2, 2012, 10:53:15 PM2/2/12
to 4Clojure
Sooo simple... Thanks indeed.
Reply all
Reply to author
Forward
Message has been deleted
0 new messages