# four-clojure-problems

committed 1e83f86

problem 33

# Files changed (2)

` # four-clojure #`
` `
`-I'm working through the 4clojure (http://4clojure.com) problem set, here are the answers that I've come up with so far`
`+I'm working through the 4clojure (http://4clojure.com) problem set, here are the answers that I've come up with so far.`
`+`
`+Do NOT consider any of these answers as the "right" way to do these, they just pass the 4clojure tests.  `
`+`
`+I'm new to clojure as I work through these and there's likely a much better/more idiomatic way of doing almost everything.`
` `
` ## License ##`
` `

`-(ns four-clojure.core)`
`+(ns four-clojure.answered)`
` `
` ; http://www.4clojure.com/problem/5`
` ; Lists: conj`
` (= (compress-seq [1 1 2 3 3 2 2 3]) '(1 2 3 2 3))`
` (= (compress-seq [[1 2] [1 2] [3 4] [1 2]]) '([1 2] [3 4] [1 2]))`
` `
`-; http://www.4clojure.com/problem/`
`-;`
`-;`
`+; http://www.4clojure.com/problem/33`
`+; Replicate a Sequence`
`+; Write a function which replicates each element of a sequence a variable number of times.`
`+(defn my-replicate [s n] (mapcat #(repeat n %) s))`
`+; or`
`+; partial can be used to get a 2nd anon function`
`+; #(mapcat (partial repeat %2) %)`
` `
`+(= (my-replicate [1 2 3] 2) '(1 1 2 2 3 3))`
`+(= (my-replicate [:a :b] 4) '(:a :a :a :a :b :b :b :b))`
`+(= (my-replicate [4 5 6] 1) '(4 5 6))`
`+(= (my-replicate [[1 2] [3 4]] 2) '([1 2] [1 2] [3 4] [3 4]))`
`+(= (my-replicate [44 33] 2) [44 44 33 33])`
` `
` ; http://www.4clojure.com/problem/`
` ;`
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.