Skip to content

Instantly share code, notes, and snippets.

View craftybones's full-sized avatar

Srijayanth Sridhar craftybones

  • Bangalore, India
View GitHub Profile
(require '[clojure.string :as cstr])
(defn pendulum [from to step]
(concat (range from to step) (range to (dec from) (- step))))
(defn rev-pendulum [from to step]
(concat (range to from (- step)) (range from (inc to) step)))
(defn line [max-size size]
(rev-pendulum (inc (- max-size size)) max-size 1))
(def remove-zeroes (partial remove zero?))
(def partition-number-sequences (partial partition-by identity))
(def pair-up (partial partition-all 2))
(def pair-partitions (partial mapcat pair-up))
(def sum-of (partial apply +))
(def sum-pairs (partial map sum-of))
(defn concat-zeroes
[coll]
(concat coll (repeat 0)))
import qualified Data.Set as S
import qualified Data.List as L
import qualified Data.Map as M
type Move = Int
type Moves = S.Set Move
chunk :: [a] -> Int ->[[a]]
chunk [] n = []
chunk l n = [(take n l)] ++ (chunk (drop n l) n)
const jdenticon = require('jdenticon');
const fs = require('fs');
const size=250;
let names=fs.readFileSync("names","utf8").split("\n");
names.forEach(name=>{
fs.writeFileSync(`${name}.png`,jdenticon.toPng(name,size));
})
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]))))