Skip to content

Instantly share code, notes, and snippets.

View craftybones's full-sized avatar

Srijayanth Sridhar craftybones

  • Bangalore, India
View GitHub Profile
@craftybones
craftybones / l-system.clj
Last active August 1, 2017 17:36
L-system implementations
(def koch-curve-right-angles
{:productions {\F "F+F-F-F+F"},
:axiom "F",
:iterations 3,
:actions {\F '(FD 20)
\+ '(LT 90)
\- '(RT 90)}})
(def sierpenski-triangle
{:productions {\F "F-G+F+G-F"
;; I've watched most, if not all of these.
Korean:
Oldboy
Sympathy for Mr Vengeance
Sympathy for Lady Vengeance
Bakjwi
JSA
Memories of Murder
Man From Nowhere
(defn max-adjacents [coll]
(map max coll (rest coll)))
(defn sum-of [prev current]
(map + current (max-adjacents prev)))
(defn max-path-sum [tree]
(first (reduce sum-of (reverse tree))))
;; To test use the following
(defn pow [x y]
(loop [i y k 1N]
(if (zero? i)
k
(recur (dec i) (* k x)))))
(count (into #{}
(for [a (range 2 101)
b (range 2 101)]
(pow a b))))
(defn closest-integer-sqrt [x]
(-> x Math/sqrt Math/floor int))
(defn prime-candidates-above-3 [x]
(lazy-seq (list* (dec (* 6 x)) (inc (* 6 x)) (prime-candidates-above-3 (inc x)))))
(def prime-candidates
(lazy-seq (list* 2 3 (prime-candidates-above-3 1))))
(def none (comp not some))
(defn take-while-adjacent
[f coll]
(lazy-seq
(when-let [s (seq coll)]
(if (f (first s) (second s))
(cons (first s) (take-while-adjacent f (rest s)))
(cons (first s) nil)))))
(ns game-of-life.core
(:require [game-of-life.utils :refer [sum-of-vectors
setify]]))
(def neighbor-offsets
(into (hash-set)
(for [i (range -1 2)
j (range -1 2)
:when (not= [i j] [0 0])]
[i j])))
(defn foo [x y]
`(intern *ns* ~x ~y))
(defmacro def-symbols-across-range
[[from step] & symbols]
(list* 'do
(map foo symbols (range))))
(def event-probability-distribution {:red 20 :green 50 :yellow 30})
(def color-generator (utils.core/random-event-generator event-probability-distribution))
(def random-colors (repeatedly color-generator))
(def sample (take 100 random-colors))
(frequencies sample)
(deftest team-score-updation
(testing "Keeps team score when no run scored"
(on-game (helper/add-dot-ball-to-game-on-over game [0 1])
(is-total-score? 0)
(is-on-over? [0 1])
(is-striker? "Kirat Boli")
(is-non-striker? "N S Nodhi")))
(testing "Updates team score and rotates strike when single run scored"
(on-game (helper/add-single-run-to-game-on-over game [0 1])
(is-total-score? 1)