Instantly share code, notes, and snippets.

# Divyansh Prakashdivs1210

• Sort options
Last active Aug 29, 2015
Babbage's Difference Engine in Python
View diff_engine.py
 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
Last active Aug 29, 2015
Babbage's Difference Engine in Clojure
View diff_engine.clj
 (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
Last active Aug 29, 2015
Simple made Easy- A Taste of Clojure for the Cjurious
View factorial.clj
 (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 ;
Last active Aug 29, 2015
One Instruction Set Computer (http://en.wikipedia.org/wiki/One_instruction_set_computer)
View impala.clj
 (ns impala) ;; =============== ;; IMPALA ;; -subleq oisc- ;; --------------- ;; github/divs1210 ;; =============== ;; Primitives ;; ==========
Last active Sep 4, 2015
View maya.clj
 (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."))))
Created Apr 2, 2016
View day6.clj
 (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]"
Last active Apr 6, 2016
This works fine for some time, but then I start getting an exception saying: "No implementation of method: :search of protocol: #'some.thing/ISearchEngine found for class: some.thing.SearchEngine"
View protocols.clj
 (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)))
Last active Jul 3, 2017
Dynamic Functional Control Flow Structures for Java
View SLIP.java
 import java.util.*; import java.util.concurrent.Callable; import java.util.function.Function; class SLIP { /** * Keywords */ public static final Object _IF = new Object(),
Last active Nov 16, 2017
Benchmark for functional-core-async
View functional-core-async-bench.clj
 (defn event [env type val] (let [rc (chan)] (>! (:queue @env) {:type type :val val :rc rc :time (:now @env)}) (
Last active Dec 1, 2017
coroutines.js walkthrough
View coroutines-js-walkthrough.md

## Channels & go

var c = chan();

go(function() {
// async block
You can’t perform that action at this time.