Skip to content

Instantly share code, notes, and snippets.

View siddMahen's full-sized avatar

Siddharth Mahendraker siddMahen

  • Toronto, Canada
View GitHub Profile
using Winston
x = Int[]
y = Int[]
for i = 2:20, j = 2:20
if (rem(i,j) != 0) && (rem(BigInt(i)^i,BigInt(j)^j) == 0)
push!(x,i)
push!(y,j)
end
var algorithms = require("algorithms"),
fs = require("fs");
var dynamicLowMem = function(capacity, values, weights){
var max = function(x, y){
return x ^ ((x ^ y) & -(x < y));
}
var items = values.length,
value = 0,
@siddMahen
siddMahen / roth.py
Last active August 29, 2015 13:56
Calculate a maximal length 3 progression free subset of [N].
from sys import argv
import math
N = int(argv[1])
S = set();
k = N
for j in range(1,N+1):
S.add(j)
@siddMahen
siddMahen / prim.py
Created January 4, 2014 22:03
Prim's algorithm, in Python.
from sys import argv
import re
# open the file and get read to read data
file = open(argv[1], "r");
p = re.compile("\d+");
# initialize the graph
vertices, edges = map(int, p.findall(file.readline()))
graph = [[0]*vertices for _ in range(vertices)]
@siddMahen
siddMahen / mandelbrot.pde
Last active December 29, 2015 22:18
Mandelbrot fractals in Processing.
int maxiter = 500;
//float zoom = 0.005;
//float fx = -0.745;
//float fy = 0.1;
float zoom = 4;
float fx = 0;
float fy = 0;
# factorization algorithm based on gcd
#
# could be vastly improved, this is barely better than
# naive
function fac(n::BigInt)
factors = Dict{BigInt,BigInt}()
while !isprime(n::BigInt)

Crypto Notes Week 2

Introduction to Block Ciphers

A block cipher is a cipher (E,D) which (given a key) takes n bits of PT as input and outputs n bits of CT.

Examples include:

  • 3DES: n = 64 bits, k = 168 bits
  • AES: n = 128 bits, k = 128, 192, 256 bits
@siddMahen
siddMahen / crypto-week-one.md
Last active August 9, 2018 14:09
Coursera cryptography lecture notes, from week one.

Crypto Notes Week 1

The first half of the course will be about sym. enc. and the second half will be about public key enc.

Introduction and Prereqs

What is cryptography?

The core of cryptography is about:

  • establishing a secret key between two parties
@siddMahen
siddMahen / sorting.js
Created May 30, 2013 22:31
written live, don't trust
/*
* Keeps a portion of the array sorted at all time,
* called the invariant.
*
* Every time you try to sort a new element, you cmpare
* against all the elems in the invariant, and put it in
* its right place.
*
* Keep doing this until the size invariant array = size orginal
* array.

Polytopes

A polytope is the convex hull of a set of points. Can see immeadately how it would be useful to know if a set of points in Rd form a polytope, linear programming!

How can we formalize this definition?

If we're only thinking about convex polytopes, we could construct a set based on the intersection of the product spaces of the multiplication of each plane through three points and the plane orthogonal to this plane.

P = \cap_{a,b,c \in S} (ab x ac) x (the normal of that plane through a or b or c)