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 Comparison | |
type Comparison = LessThan | Equal | GreaterThan |
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 Natural | |
type Natural = One | SuccessorOf of Natural | |
let Two = SuccessorOf One | |
let Three = SuccessorOf Two | |
let Four = SuccessorOf Three | |
// and so on | |
// given two natural numbers, either they're *equal*, or one is *greater than* the other |
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
from collections import deque | |
def partition(a, lo, hi): | |
"""partition a[lo] to a[hi] using a[hi] as the pivot""" | |
pivot_value = a[hi] | |
insert_at = lo | |
for i in range(lo, hi): | |
if a[i] < pivot_value: | |
a[i], a[insert_at] = a[insert_at], a[i] | |
insert_at += 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
def target_fn(theta): | |
"""want to minimize squared errors as a function of *theta*, so we hardcode in the data""" | |
alpha, beta = theta | |
return sum_of_squared_errors(alpha, beta, num_friends_good, daily_minutes_good) | |
def gradient_fn(theta): | |
"""similarly, need gradient as a function of *theta*, so hardcode in the data""" | |
alpha, beta = theta | |
result = [0, 0] | |
for x_i, y_i in zip(num_friends_good, daily_minutes_good): |
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
# got the idea from https://gist.github.com/tshauck/6ebb0c2d6adc667608b8 | |
def switch(*args, default=None): | |
try: | |
return next(value for cond, value in args if cond) | |
except StopIteration: | |
return default | |
x = 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
# Rewrite of Norvig's monopoly simulator to avoid global state | |
# except for `board`, which is used immutably. | |
# http://nbviewer.ipython.org/url/norvig.com/ipython/Probability.ipynb | |
import random | |
split = str.split | |
# The board: a list of the names of the 40 squares | |
board = split("""GO A1 CC1 A2 T1 R1 B1 CH1 B2 B3 | |
JAIL C1 U1 C2 C3 R2 D1 CC2 D2 D3 |
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
const State = Immutable.Record({count:0}); | |
const state$ = action$.startWith(new State()) | |
.scan((state, delta) => state.updateIn(['count'], count => count + delta)); | |
const vtree$ = state$.map(...) |
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
width :: Number | |
width = 600.0 | |
height :: Number | |
height = 600.0 | |
-- Generate a Drawing of n deterministic points | |
nonRandomPoints :: Int -> Drawing | |
nonRandomPoints n = foldMap makeCircle points | |
where |
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 (Unit) | |
import Control.Monad.Eff (Eff) | |
import Control.Monad.Eff.Console (CONSOLE, log) | |
import Debug.Trace (trace) | |
import Pux (start, renderToDOM, EffModel(), App) | |
import Prelude ((+), (-), const, show, (++), pure, ($), (>>=)) | |
import Pux.Html (Html, (!), (#), bind, div, span, button, text) | |
import Pux.Html.Events (onClick) |
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
""" | |
how to count as fast as possible | |
(numbers from Python 3.5.2 on a Macbook Pro) | |
YMMV, but these results are pretty stable for me, say +/- 0.1s on repeated runs | |
""" | |
from collections import Counter, defaultdict | |
import random | |
random_numbers = [random.randrange(10000) for _ in range(10000000)] |
OlderNewer