Skip to content

Instantly share code, notes, and snippets.

View ruggeri's full-sized avatar
🌕
🌀_🌀

Ned Ruggeri ruggeri

🌕
🌀_🌀
View GitHub Profile
import random
import re
import string
def load_dictionary():
with open("dictionary.txt") as f:
return f.read().splitlines()
def filter_dictionary(dictionary):
new_dictionary = []
@ruggeri
ruggeri / max.cc
Last active March 29, 2022 22:00
Calculate A Maximum Value Recursively
#include <iostream>
#include <stdexcept>
int max(int numbers[], unsigned int len)
{
std::cout << "len=" << len << ": starting function." << std::endl;
if (len == 0)
{
throw std::invalid_argument("len must not be zero");
@ruggeri
ruggeri / part1.md
Last active April 3, 2023 00:21
Godel's First Incompleteness Theorem

Warmup: What Is A Programming Language?

A proof is a argument that a statement is true, where the argument is written in a formalized, very specific language. The concept of what a proof is can be confusing, so I want to make an extended analogy to computer programs and programming languages.

(I think that people who know computer programming are in a uniquely good position to understand mathematical logic.)

@ruggeri
ruggeri / qsort.hs
Created October 10, 2018 06:12
Haskell Quicksort V2
import Control.Monad (forM, liftM)
import Data.Array.IO (IOUArray, getElems, newListArray)
import Data.Array.Base (unsafeRead, unsafeWrite)
import Data.Function ((&))
import Data.Time.Clock (NominalDiffTime, diffUTCTime)
import Data.Time.Clock.POSIX (getPOSIXTime, posixSecondsToUTCTime)
import System.Random.MWC (create, uniformR)
-- TODO: I should be able to do this with the ST monad, but I'm not
-- smart enough for that yet.
import Control.Monad
import Data.Array.IO
import System.Random
-- TODO: I should be able to do this with the ST monad, but I'm not
-- smart enough for that yet.
-- ArraySlice data type. I probably should be able to parameterize
-- over the kind of MArray. Indeed, ArraySlice probably can implement
-- MArray itself!

unit normal = normal(mean = 0, stddev = 1) What does stddev mean?

Mean is the expected value of the random variable: mean = \Int Pr(x) x It's not the most likely value necessarily. That would be the mode.

Let's say you sample from the normal distribution. What is the expected value of the squared error of the mean and the sample? How good is the mean value as a predictor of samples drawn from the normal distribution

The less good the mean value is at predicting, the more "random" the normal distribution is. The "wider" the dispersion.

@ruggeri
ruggeri / graphs.md
Last active March 12, 2018 17:31
Graph Algorithms

Graph Algorithms


Graph Types

  • Vertices and edges
    • Vertex: city.
    • Edge: road.
  • Undirected vs directed

Binary Search Trees


Operations

  • find
  • insert
  • delete
  • Each has time complexity proportional to depth of the tree.
@ruggeri
ruggeri / heaps.md
Last active February 26, 2018 02:01

Heaps

Priority Queue

Heaps are an implementation of the priority queue abstract data type:

  • insert(entry, priority).
    • priority is an integer priority. Entries with "higher priority" will be extracted before entries with "lower priority."
  • Lower number often is "higher priority." This makes sense