Skip to content

Instantly share code, notes, and snippets.

@kartikshah
kartikshah / project.clj
Created February 8, 2011 07:01
RSS Feeder lein Project File
(defproject rss-feeder "1.0.0-SNAPSHOT"
:description "RSS Feeder - Filters RSS feed for given keywords"
:dependencies [[org.clojure/clojure "1.2.0"]
[org.clojure/clojure-contrib "1.2.0"]
[clj-http "0.1.2"]]
:main rss.core)
@kartikshah
kartikshah / 4clojure-21.clj
Created May 7, 2011 15:14
Solution to 4clojure 21
;http://4clojure.com/problem/22
;count without using count
(#(loop [myseq % i 0]
(if (empty? myseq)
i
(recur (next myseq) (+ i 1))))
[1 2 3 4]) ; or provide any list arg here
@kartikshah
kartikshah / 4clojure33.clj
Created May 15, 2011 20:28
4Clojure - 33
(fn [xs n] (if (= n 1) xs (apply interleave (repeat n xs))))
(fn [xs1 xs2] (flatten (reverse (seq (zipmap xs1 xs2)))))
(fn [k xs] (conj (vec (interleave xs (vec (repeat ( - (count xs) 1) k)))) (last xs)))
@kartikshah
kartikshah / 4clojure41.clj
Created May 15, 2011 21:10
4Clojure - 41
(fn [xs n] (keep-indexed (fn [idx v] (if (zero? (mod (+ idx 1) n)) nil v)) xs))
@kartikshah
kartikshah / 4clojure42.clj
Created May 15, 2011 21:16
4Clojure - 42
(defn fct [n] (if (= n 1) 1 (reduce #(* %1 %2) (range 1 (+ n 1)))))
@kartikshah
kartikshah / 4clojure46.clj
Created May 16, 2011 05:24
4Clojure - 46
((partial (fn [fns x y] (fns y x)) nth) 2 [1 2 3])
@kartikshah
kartikshah / 4clojure44.clj
Created May 17, 2011 01:19
4Clojure - 44
(defn rotate [n xs]
(let [cnt (count xs)
modn (mod n cnt)]
(flatten (list (take-last (- cnt modn) xs) (take modn xs)))))
@kartikshah
kartikshah / 4clojure55.clj
Created May 17, 2011 03:00
4Clojure - 55
(fn [xs]
(let [m (group-by (fn [x] x) xs)]
(zipmap (keys m) (map count (vals m)))))