This file contains 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
from math import comb | |
import numpy as np | |
import matplotlib.pyplot as plt | |
from tqdm import trange | |
''' | |
There are `N` items. We select `n` (NOT necessarily unique) items per round with replacement. Assume `1 <= n`. | |
Consider the Random Process X_0, X_1, X_2, .... | |
Each `X_i` represents the number of unique items selected through round `i`. |
This file contains 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
''' | |
Motivated by | |
https://www.youtube.com/watch?v=BwHspSCXFNM&list=PLi01XoE8jYoi3SgnnGorR_XOW3IcK-TP6&index=7 | |
''' | |
__author__ = 'Tim Gianitsos' | |
from random import randint | |
import numpy as np |
This file contains 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 numpy as np | |
__author__ = 'Tim Gianitsos' | |
def display_img(img): | |
''' | |
img: a 2D array of ints | |
''' | |
dark_black = '\u001B[40m ' | |
light_black = '\u001B[100m ' |
This file contains 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
from itertools import chain, combinations | |
import json | |
import warnings | |
__author__ = 'Tim Gianitsos' | |
class PowerSetCounter: | |
''' | |
Author: Tim Gianitsos | |
Count all combinations of occurences of the given iterable and their attributes |
This file contains 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
# Compute RSA encryption in python | |
# Author: Tunde | |
import random | |
import math | |
import argparse | |
import re | |
KEY_INT = 100 # we define the near max value to get its random number for key | |
def main(): |
This file contains 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
from time import time, sleep | |
__author__ = 'Tim Gianitsos' | |
class Stopwatch: | |
''' | |
Display loop progress | |
Wrap an iterable object, and obtain automatic updates on the progress of iteration. | |
Example: | |
Replace `for i in range(15):` with `for i in Stopwatch(range(15)):` |
This file contains 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 java.math.BigInteger; | |
import java.util.Scanner; | |
/* | |
To run, use | |
`javac *.java && java -ea BinomialCoefficients` | |
Author: Tim Gianitsos | |
*/ | |
public class BinomialCoefficients |
This file contains 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
from collections import Counter | |
from string import punctuation | |
from os.path import split | |
import sys | |
__author__ = 'Tim Gianitsos' | |
def main(filename=None, num_display=30): | |
c = Counter(s for t in open(filename).read().split() if (s:=t.lower().replace(fr'“‘”’{punctuation}', '')).isalpha()) | |
mc = c.most_common() |
This file contains 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
''' | |
Union-find data structure. Based on Josiah Carlson's code, | |
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/215912 | |
with significant additional changes by D. Eppstein | |
https://www.ics.uci.edu/~eppstein/PADS/UnionFind.py | |
with additional changes by Tim Gianitsos | |
''' | |
class UnionFind: |