Skip to content

Instantly share code, notes, and snippets.

View taylorwood's full-sized avatar

Taylor Wood taylorwood

View GitHub Profile
@taylorwood
taylorwood / emoji.clj
Last active December 15, 2017 17:02
Parse/render Unicode.org Emoji data https://www.unicode.org/reports/tr51/#Data_Files
(ns unicode.emoji
"Parses Unicode.org Emoji specifications."
(:require [clojure.java.io :as io]
[clojure.string :as cs]))
(defn slurp-lines
"Returns lines from unicode emoji file. Optionally reads file of same name
from resources."
[file & [resource?]]
(-> (if resource?
@taylorwood
taylorwood / parts.clj
Created October 22, 2017 17:10
Recursive function for integer partitions
(defn parts
"Returns integer partitions for n."
([n]
(parts n n [] []))
([n m acc prefix]
(if (= 0 n)
(conj acc prefix)
(reduce
(fn [st i]
(into st (parts (- n i) i acc (conj prefix i))))
@taylorwood
taylorwood / infix-spec.clj
Created October 8, 2017 00:56
Recursive clojure.spec for grouped/nested infix expressions http://taylorwood.github.io/2017/10/04/clojure-spec-boolean.html
(ns playground.test
(:require [clojure.spec.alpha :as s]
[clojure.spec.gen.alpha :as sgen]
[clojure.spec.test.alpha :as stest]
[clojure.string :as cs]
[clojure.walk :as walk]))
(def op-keys #{:and :or})
(s/def ::expression
@taylorwood
taylorwood / Solutions.fs
Created September 14, 2016 21:56
Phone screen challenge
// A sequence of integers is defined as F(N) = F(N-1) * F(N-2),
// with F(0) = 1 and F(1) = 2.
// Write a function which, given N, prints N and F(N)
// f(2) = F(2-1) * F(2-2) = F(1) * F(0) = 2 * 1 = 2
// f(3) = f(3-1) * f(3-2) = f(2) * f(1) = 2 * 2 = 4
// f(4) = f(4-1) * f(4-2) = f(3) * f(2) = 4 * 2 = 8
// f(5) = f(5-1) * f(5-2) = f(4) * f(3) = 8 * 4 = 32
// f(6) = f(6-1) * f(6-2) = f(5) * f(4) = 32 * 8 = 256
// recursive
@taylorwood
taylorwood / Exercise.fsx
Last active September 23, 2018 22:18
Relay Foods exercise
open System
// Data types //
/// Describes an Address, its physical location, and the times it will be occupied.
[<StructuredFormatDisplay("{Name}")>]
type Address = {
Name: string
Street: string
City: string