Skip to content

Instantly share code, notes, and snippets.

View swairshah's full-sized avatar

swairshah swairshah

  • mode.ai
  • Palo Alto, CA
View GitHub Profile
@swairshah
swairshah / simulate.jl
Last active March 28, 2020 19:40
3blue1brown like infection simulation in Julia.
using Distributions, Plots, Random
using StatsBase, StatsPlots
using Distances
function init(size::Int, I₀=0.1)
S₀ = 1 - I₀
x = rand(Uniform(0, 10), size, 2)
v = zeros(size, 2)
status = sample([:S, :I, :R], Weights([S₀, I₀, 0]), size)
x, v, status
import random
import itertools
import numpy as np
# counter example:
# a = np.array([25, 1, 46, 25, 45, 6, 25, 43, 9, 3, 21, 34, 41, 32, 36, 12, 33,
# 7, 42, 50, 22, 37, 16, 31, 3, 44, 28, 8, 4, 41, 15, 19, 29, 10,
# 31, 14, 2, 17, 31, 16, 9, 15, 15, 40, 37, 14, 10, 2, 19, 9])
# b = np.array([ 4, 37, 43, 11, 26, 17, 35, 42, 47, 31, 49, 39, 47, 39, 37, 15, 35,
# 26, 25, 43, 47, 49, 19, 42, 28, 49, 18, 19, 48, 35, 1, 15, 40, 15,
import numpy as np
from numpy.random import uniform as unif
def euclidean_dist(x,y):
return np.sqrt(sum((x-y)**2))
def method1(n, N = 10000):
dist = 0
for i in range(N):
@swairshah
swairshah / time_qsort.py
Created August 24, 2012 10:30
Python quicksort comparision
from random import randint
import timeit
import sys
def qsort2(list):
if list == []:
return []
else:
pivot = list[0]