This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def diff(seq): | |
""" [1,4,9] => [3,5] """ | |
return map(lambda x,y: x-y, seq[1:], seq[:-1]) | |
def triangle(seq): | |
""" [1,4,9] => [[1,4,9],[3,5],[2]] """ | |
diffs=[seq] | |
for i in range(1, len(seq)): | |
diffs.append(diff(diffs[i-1])) | |
return diffs |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defn diffs | |
"(diffs [1 4 9]) => (3 5)" | |
[alist] | |
(map - (rest alist) alist)) | |
(defn infer | |
"(infer [1 4 9]) => (1 4 9 16 25 ...)" | |
[pattern] | |
(->> (take (count pattern) (iterate diffs pattern)) | |
(map last) reverse |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns maya) | |
(defmacro math-> | |
" (math-> 1 + 5 * 2 / 3) ;=> (-> 1 (+ 5) (* 2) (/ 3)) ;=> 4 " | |
[exp & f-x-pairs] | |
(if (even? (count f-x-pairs)) | |
`(-> ~exp | |
~@(for [[f x] (partition 2 f-x-pairs)] | |
(list f x))) | |
(throw (Exception. "f-x-pairs should be even.")))) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns factorial) | |
;;---------------- | |
;;A Simple Problem | |
;;---------------- | |
;The factorial function can be written as: | |
; factorial(n) = 1 * 2 * 3 * ... * n | |
; | |
;Let's take the case of factorial(5): | |
; 1 * 2 * 3 * 4 * 5 | |
; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns impala) | |
;; =============== | |
;; IMPALA | |
;; -subleq oisc- | |
;; --------------- | |
;; github/divs1210 | |
;; =============== | |
;; Primitives | |
;; ========== |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
""" | |
Download a specific folder from a github repo: | |
gitget.py https://github.com/divs1210/kilvish/tree/master/examples/bricksnball | |
""" | |
__author__ = 'Divyansh Prakash' | |
import sys | |
import subprocess |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns aoc.day6 | |
(:require [clojure.core.reducers :as r] | |
[clojure.set :as cset] | |
[clojure.string :as s])) | |
(defn part-1-input [] | |
(.trim (slurp "resources/day6-part1-input"))) | |
(defn str->point | |
"(str->point \"0,0\") => [0 0]" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defprotocol ISearchEngine | |
"Search the web" | |
(search [engine term] "Search the web for a single (one-word) term.")) | |
(defrecord SearchEngine [url] | |
ISearchEngine | |
(search [this term] | |
(-> (str (:url this) term) | |
http/get deref :body))) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns hmap) | |
(defmacro hmap [& kvs] | |
"Returns an immutable hashmap. | |
Keys must be compile-time constants." | |
(if (even? (count kvs)) | |
(let [tups (partition 2 kvs) | |
keys (mapv first tups) | |
kvs+ (concat kvs [::keys keys])] | |
`(fn [k#] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import types | |
# Helpers | |
# ======= | |
def _obj(): | |
'''Dummy object''' | |
return lambda: None | |
_FILLER = _obj() |
OlderNewer