Skip to content

Instantly share code, notes, and snippets.

View uroybd's full-sized avatar

Utsob Roy uroybd

View GitHub Profile
@uroybd
uroybd / move.clj
Last active August 29, 2015 14:27
(defn move
([dvec direction indx]
(cond (= direction :up) (move dvec :swap indx (dec indx))
(= direction :down) (move dvec :swap indx (inc indx))
:else (println "Wrong Number of args")))
([dvec direction indx1 indx2]
(if (= direction :swap)
(assoc dvec indx2 (nth dvec indx1) indx1 (nth dvec indx2))
(println "Invalid arguments"))))
@uroybd
uroybd / html-o-matic
Created August 17, 2015 11:52
Filter html
(use 'pl.danieljanus.tagsoup)
(use 'hiccup.core)
(defn parser [input]
(pl.danieljanus.tagsoup/parse
(java.io.ByteArrayInputStream.
(.getBytes
(slurp input)))))
(defn dissoc-all [dmap keys]
@uroybd
uroybd / html-o-matic
Created August 16, 2015 08:52
Html Cleaner
(use 'pl.danieljanus.tagsoup)
(use 'hiccup.core)
(defn parser [file_path]
(pl.danieljanus.tagsoup/parse (java.io.ByteArrayInputStream. (.getBytes (slurp file_path)))))
(defn attr_filter [element]
(cond
(map? element) {}
(= (type []) (type element)) (mapv identity (map attr_filter element))
@uroybd
uroybd / eular1.clj
Created August 12, 2015 04:47
multiplse of 3 and 5
(defn bigboy [x]
(reduce + (distinct (concat (take-nth 3 (range x)) (take-nth 5 (range x))))))
(loop [start 1 end (Integer/parseInt (read-line))]
(when (<= start end)
(println (bigboy (Integer/parseInt (read-line))))
(recur (inc start) end)))
@uroybd
uroybd / Hackerrank e^x
Last active August 29, 2015 14:23
Hackerrank e^x
(loop [test-case-remaining (Integer/parseInt (read-line))]
(while (not= 0 test-case-remaining)
(do (println (let [factorial (fn [n]
(reduce * (take n (range 1 (inc n)))))
to-the-power (fn [n m]
(reduce * (repeat m n)))
e-to-the-power-x (fn [x]
(inc (apply + (map #(float (/ (to-the-power x %)
(factorial %)))
(range 1 10)))))]