Skip to content

Instantly share code, notes, and snippets.

@Agnishom
Agnishom / dijkstra.py
Created March 30, 2017 06:11
Dijkstra's Algorithm
from fibHeap import FibonacciHeap
def dijkstra(adjList, source, sink = None):
n = len(adjList) #intentionally 1 more than the number of vertices, keep the 0th entry free for convenience
visited = [False]*n
distance = [float('inf')]*n
heapNodes = [None]*n
heap = FibonacciHeap()
for i in range(1, n):
@Agnishom
Agnishom / kosaraju.py
Last active March 31, 2017 06:33
Strongly Connected Components
def kosaraju(outList):
n = len(outList) # n is 1 more than the number of vertices, for convenience
visited = [False]*n
components = [None]*n
L = []
def visit(u):
if not visited[u]:
visited[u] = True
for v in inList[u]:
@Agnishom
Agnishom / medianOfMedians.hs
Last active September 15, 2017 09:21
Median Of Medians
import Data.List
median :: (Show a, Ord a) => [a] -> a
median xs = select ((length xs) `div` 2) xs
select :: (Show a, Ord a) => Int -> [a] -> a
select i xs
| n <= 5 = (sort xs) !! i
| lengthLower == i = medianOfMedians
| lengthLower < i = select (i - lengthLower - 1) upperPartition
@Agnishom
Agnishom / ries.c
Created December 28, 2016 03:56
RIES Source
/* ries.c
RIES -- Find Algebraic Equations, Given Their Solution
Copyright (C) 2000-2016 Robert P. Munafo
This is the 2016 Oct 08 version of "ries.c"
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
@Agnishom
Agnishom / castelNum.md
Created November 5, 2016 03:31
Castel Numbers

Castel - A whole new set of numbers that humans can't actually understand it's existence. Here well see what is a 'Castel' number and 'Casteline' numbers, how are they different from each other and what makes them unique from other set of numbers (ie, Real numbers, Imaginary numbers, Complex numbers).

[[heading|Introduction]]

Before dealing with this refer Natural, Whole, Integer, Rational, Irrational, Real, Imaginary and Complex numbers.

[[heading|Casteline Numbers]]

A Casteline number is denoted by (\mathbb{L}). Set of all Casteline number is infinite, unlike Castel numbers. If you grab a look at Real and Complex numbers you will get an

@Agnishom
Agnishom / chirps.csv
Created June 24, 2016 17:17
Cricket Chirp Data
Chirps Temperature
20 88.59999847
16 71.59999847
19.79999924 93.30000305
18.39999962 84.30000305
17.10000038 80.59999847
15.5 75.19999695
14.69999981 69.69999695
17.10000038 82
15.39999962 69.40000153
@Agnishom
Agnishom / finiteDiff.py
Last active June 20, 2016 05:07
Finite Differences
import numpy
import matplotlib.pyplot
class System:
def __init__(self,length,height,gridSize):
self.length = length
self.height = height
self.gridSize = gridSize
self.grid = numpy.empty((self.height/self.gridSize + 1, self.length/self.gridSize + 1,))
self.__str__ = self.grid.__str__
@Agnishom
Agnishom / trie.cpp
Created April 29, 2016 16:50
Tries
#include <iostream>
#include <string>
struct TrieNode{
int partial = 0;
TrieNode* next[26] = {nullptr};
};
class Contacts{
TrieNode root;
@Agnishom
Agnishom / piHan
Created April 28, 2016 14:41
Pi Han's Paradox
Part I - Curry's Paradox
Let us explore a proposition A defined as (if A then B). The following argument holds:
1. A := if A then B [definition]
2. if A then A [Rule of Assumption]
3. if A then (if A then B) [definition of A]
4. if A then B [contraction]
5. A [definition of A]
@Agnishom
Agnishom / polyethene.py
Last active December 30, 2015 16:31
Sage simulation of the Chain Length Problem
def reaction(nEthene,nFreeRadicals):
FreeRadicals = [0]*nEthene
ClosedChains = [0]*nEthene
FreeRadicals[0] = nFreeRadicals
nClosedChains = 0
while nFreeRadicals:
randomType1 = GeneralDiscreteDistribution([nEthene, nFreeRadicals, nClosedChains]).get_random_element()
if randomType1 == 0: #Ethene