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
| (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)) |
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 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))) |
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 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) |
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
| 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)); | |
| }) |
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
| 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)) ++ "/") |
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
| let greeting="Hello Universe"; | |
| console.log(greeting); |
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
| 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 |
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
| 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] |
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 -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]}) |
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 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])))) |