Skip to content

Instantly share code, notes, and snippets.

View craftybones's full-sized avatar

Srijayanth Sridhar craftybones

  • Bangalore, India
View GitHub Profile
repeatChar char times = take times (repeat char)
filledLine = repeatChar '*'
dashedLine = repeatChar '-'
emptyLine = repeatChar ' '
hollowLine width = take width ("*" ++ (emptyLine (width - 2)) ++ "*")
topLine width = take width ("/" ++ (emptyLine (width - 2)) ++ "\\")
bottomLine width = take width ("\\" ++ (emptyLine (width - 2)) ++ "/")
let greeting="Hello Universe";
console.log(greeting);
data Tree a = EmptyTree | Node a (Tree a) (Tree a) deriving (Show)
createTree :: (Ord a) => a -> Tree a
createTree x = Node x EmptyTree EmptyTree
insert :: (Ord a) => Tree a -> a -> Tree a
insert EmptyTree x = Node x EmptyTree EmptyTree
insert (Node x left right) y
| x == y = Node x left right
| x > y = Node x (insert left y) right
by6 :: Int -> [Int]
by6 n = [(6*n)-1,(6*n)+1]
genPrimeCandidates :: Int -> [Int]
genPrimeCandidates n = (by6 n) ++ genPrimeCandidates (n+1)
primeCandidates :: [Int]
primeCandidates = [2,3] ++ (genPrimeCandidates 1)
primeCandidatesBelow :: Int -> [Int]
(def -directions [:N :E :S :W :N])
(defn position [c h]
{:co-ord c :heading h})
(def moves {:N [identity inc]
:E [inc identity]
:S [identity dec]
:W [dec identity]})
(defn sqr [x] (* x x))
(defn winning-combinations [size-of-grid]
(let [indices (range 1 (inc (sqr size-of-grid)))
rows (partition size-of-grid indices)
cols (apply map list rows)
diagonal-1 (take-nth (inc size-of-grid) indices)
diagonal-2 (take-nth (dec size-of-grid)
(range size-of-grid (sqr size-of-grid)))]
(map set (concat rows cols [diagonal-1 diagonal-2]))))
@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))))