View arc_segment_intersection.js
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
// returns an array of real solutions to the quadratic ax^2 + bx + c = 0 | |
const quadratic = (a, b, c) => { | |
if (a === 0) return [ -c/b ]; | |
const discriminant = b*b - 4*a*c; | |
if (discriminant < 0) { | |
return []; | |
} else { | |
const y = - b / (2 * a); | |
const x = Math.sqrt(discriminant) / (2 * a); | |
return [y + x, y - x]; |
View banach-tarski.purs
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
module BanachTarski where | |
import Prelude | |
import Data.Foldable (and, foldr) | |
import Data.Group.Free (FreeGroup(..), Signed(..), free) | |
import Data.List ((:)) | |
import Data.Tuple (Tuple, snd) | |
import Math (Radians, acos, cos, sin) |
View hutton.purs
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
module Main where | |
import Prelude hiding (between) | |
import Control.Monad.Eff (Eff) | |
import Data.Array (foldr, many, reverse, some, uncons) | |
import Data.Bifunctor (lmap) | |
import Data.Either (Either) | |
import Data.Functor (voidRight) | |
import Data.Maybe (Maybe(..)) |
View ProfunctorLens.js
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
/** | |
* Lens types. | |
* =========== | |
* | |
* a * b = {fst: a, snd: b} | |
* a + b = {index: Boolean, value: a | b} | |
* | |
* Iso s t a b = forall (~>) . Profunctor (~>) => (a ~> b) -> (s ~> t) | |
* Lens s t a b = forall (~>) . Strong (~>) => (a ~> b) -> (s ~> t) | |
* Prism s t a b = forall (~>) . Choice (~>) => (a ~> b) -> (s ~> t) |
View purescript-confusion.purs
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
module Example.LSystem where | |
import Prelude | |
import Control.Monad.Eff (Eff) | |
import Data.Array (foldM) | |
import Data.Maybe (Maybe(..)) | |
import Graphics.Canvas (CANVAS, closePath, fillPath, getCanvasElementById, getContext2D, lineTo, moveTo, setFillStyle, setStrokeStyle, strokePath) | |
import Math as Math | |
import Partial.Unsafe (unsafePartial) |
View binary_tree_invert.hs
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
{-# LANGUAGE DeriveFunctor #-} | |
data MaybePair a = Pair (Maybe a) (Maybe a) | |
deriving (Eq, Show, Functor) | |
data BinaryTree a = | |
Node a (MaybePair (BinaryTree a)) | |
deriving (Eq, Show) | |
invert :: BinaryTree a -> BinaryTree a |
View monadic-fizzbuzz.js
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
/*** | |
You've probably seen FizzBuzz before. If you need a reminder, the problem is | |
this: Print out a list of numbers from 1 to 100, except that if a number's | |
divisible by 3, replace it with "Fizz", and if it's divisible by 5, replace it | |
with "Buzz". If it's divisible by 3 and 5, replace it with "FizzBuzz". | |
This is pretty straightforward to do in JavaScript with a for loop and some | |
if-then blocks, but it quickly gets more complicated. What if we want to add | |
"Quux" at the end of every number divisible by 7? And also add "Prime" at the |
View hart-mas-colell.py
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
# Written by Daniel Filan (2017) based on the algorithm described in Hart and Mas-Colell (2000) | |
# This code is in the public domain. | |
# This script implements the Hart-Mas-Colell algorithm for finding correlated | |
# equilibria in many-player many-action games via the players following a simple | |
# adaptive procedure. | |
import numpy as np | |
import random |