This file contains hidden or 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
# base_to_decimal.py | |
""" | |
a base n to decimal converter and vice versa, | |
as well as base to base converter | |
Not all decimals can be expressed in a certain base as a | |
finite sequence; these are handled with an exception after | |
exceeding TERMINATION_LENGTH | |
characters allowed are 0-9 followed by A-Z |
This file contains hidden or 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
/*---------------------------- | |
Collection of states {s_i}. Sequence of inputs (say characters) {c_j}. State transition function T: (s_i, c_j) |-> s_k | |
. For pattern matching we would say one such state corresponds to a ‘match’. For string matching allowed state transitions | |
are increments until match found or ‘back to the beginning’ aka start over. | |
-----------------------------*/ | |
#include <stdio.h> | |
#include "string.h" |
This file contains hidden or 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
# stack_computations.py | |
""" | |
Simple example stack computations | |
""" | |
""" | |
Stack diagram | |
f(n) | |
f(n-1) |
This file contains hidden or 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
/*--------------------------------- | |
minimax example | |
/ | \ | |
/ \ / \ / | \ | |
/\ /\ /\ /\ /\ /\ /\ | |
2 7 8 1 4 5 9 0 3 6 5 1 2 1 | |
becomes | |
7 |
This file contains hidden or 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 random | |
EMPTY = ' ' | |
PLAYER1 = 'x' | |
PLAYER2 = 'o' | |
DIM = 3 | |
def player_wins(state, player): | |
anycol = any(all(state[i][j] == player for i in range(DIM)) for j in range(DIM)) | |
anyrow = any(all(state[j][i] == player for i in range(DIM)) for j in range(DIM)) |
This file contains hidden or 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
#include <iostream> | |
#define SIZE 3 | |
#define EMPTY 'e' | |
#define BIGNUM 100 | |
#define MAXNUMSTATES 10000 | |
enum Player {Player1 = 'x', Player2 = 'o'}; | |
struct state { |
This file contains hidden or 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
""" | |
Program demonstration that a single-layer linear autoencoder | |
is equivalent to principal component projection | |
""" | |
import numpy as np | |
import tensorflow as tf | |
class A1(object): |
This file contains hidden or 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
""" | |
a basic redundant bits encoder-decoder | |
""" | |
import json | |
import random | |
import sys | |
SAMPLE_PAYLOAD = {"foo": 1, "bar": 2} | |
FLIP_PROB = 0.05 |
This file contains hidden or 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 matplotlib.pyplot as plt | |
def hom1(f, x0, dx0, delta, n): | |
sol = [x0] | |
x1, dx = x0 + dx0 * delta, dx0 | |
for _ in range(n-1): | |
x0, x1, dx = x1, f(x0) * delta + x0, 1.0 * (x1 - x0) / delta | |
sol.append(x0) | |
return sol |
This file contains hidden or 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
# insecure_deserialization.py | |
""" | |
as stated in the docs (https://docs.python.org/3/library/pickle.html): | |
'Warning The pickle module is not secure. Only unpickle data you trust.' | |
""" | |
import os |