This file contains 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
;; definitely slow | |
(defn quicksort [unsorted] | |
(if (empty? unsorted) | |
unsorted | |
(let [pivot (first unsorted) | |
left (filter #(< % pivot) (next unsorted)) | |
right (filter #(> % pivot) (next unsorted)) | |
] | |
(concat (quicksort left) [pivot] (quicksort right)) |
This file contains 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
// the intention was to make a gist, hence everything is put | |
// into one file. | |
var expect = require('chai').expect; | |
function treeNode(key) { | |
this.key = key; | |
this.left = null; | |
this.right = null; |
This file contains 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 Data.List hiding (find ) | |
import Data.Char | |
import System.FilePath.Find -- Sullivan's filemanip library | |
-- Responsible for splitting each file name into a list of substrings | |
myFunction :: [Char] -> String -> [String] | |
myFunction slig [] = [] | |
myFunction splig something@(x:xs) = if (elem x splig ) then ( myFunction splig xs ) |
This file contains 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
var _ = require('lodash'); | |
var moment = require('moment'); | |
var RBTree = require('bintrees').RBTree; | |
var time = require('performance-now'); | |
var TEST_NUMBER = 100000 | |
function randomRangeGenerator(min,max){ | |
var a = Math.floor(min + Math.random()*(max-min)); |
This file contains 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
-- round robin based scheduler based on Chris Okasaki's stack Overflow answer | |
-- the algorithm is as follows assuming you have 6 teams | |
-- arange them as (clockwise) | |
-- | |
-- | 0, 1, 2 | now keep 0 fixed and rotate as such | 0, 5, 1 | | |
-- | 5, 4, 3 | | 4, 3, 2 | | |
-- leading to games (0,4), (5,3) and (1,2) | |
-- rotate again with 0 fixed and you get | 0, 4, 5 | | |
-- | 3, 2, 1 | |
This file contains 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
package main | |
import ( | |
"crypto/sha1" | |
"fmt" | |
"io/ioutil" | |
"log" | |
"os" | |
) |
This file contains 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
(defun dot->png (fname thunk) | |
(with-open-file (*standard-output* | |
fname | |
:direction :output | |
:if-exists :supersede) | |
(funcall thunk)) | |
(sb-ext:run-program "/usr/local/bin/dot" (list "-T" "png" "-O " fname) :error t) | |
) |
This file contains 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
<!DOCTYPE html> | |
<html> | |
<head> | |
<script src="https://cdnjs.cloudflare.com/ajax/libs/rxjs/4.0.6/rx.all.js"></script> | |
<title>Rxjs start</title> | |
</head> | |
<body> | |
<button id="egg">Mash</button> | |
<button id="reset">Reset</button> | |
<div id="display">0</> |
This file contains 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
;; http://learnyouahaskell.com/higher-order-functions | |
;; answer -> 1666500 | |
(let [coll (iterate (partial + 2) 1) | |
sq (fn [x] (* x x))] | |
(reduce (fn [a,x] (if (> (sq x) 10000) (reduced a) (+ a (sq x)))) | |
coll)) |
This file contains 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 generate-primes-till [x] | |
;; sieve of eratosthenes | |
(let [coll (take-while #(< % x) (iterate (partial + 2) 3)) | |
sq (fn [x] (* x x)) | |
not-a-multiple (fn [x a] (or (= a x) (> (mod a x) 0))) | |
steps (take-while #( < (sq %) x) coll)] | |
(cons 2 (reduce (fn [a,x] (filter #(not-a-multiple x %) a)) | |
coll steps)))) | |
(println (generate-primes-till 1000 )) |
OlderNewer