Skip to content

Instantly share code, notes, and snippets.

View ryu577's full-sized avatar

Rohit Pandey ryu577

View GitHub Profile
@ryu577
ryu577 / tax_calc.py
Last active April 6, 2024 19:18
Given tax brackets and tax rates at those brackets, calculates the tax you owe.
# Brackets always start at 0. Enter the beginning of each tax bracket in the array
# all the way to the last one.
brckts = [0,11000,44725,95375,182100,231250,578125]
rates = [.1, .12, .22, .24, .32, .35, .37]
def calc_tax(brckts, rates, taxable_income=100000):
tax = 0
for i in range(len(rates)-1):
if taxable_income > brckts[i+1]:
@ryu577
ryu577 / tst.md
Last active October 1, 2023 17:27
Testing if latex works in .md files on a gist

Let's try some Math.

$$a^2+b^2 = 5$$

$$\frac{a}{b} = 21$$

@ryu577
ryu577 / 4dsphere_objects.py
Created June 10, 2023 03:32
Performing rotations repeatedly in 4-d space.
import numpy as np
from PIL import Image, ImageDraw
def rotation(n, theta=np.pi/3):
"""
Returns a general rotation matrix of any dimensionality.
This is achieved by a sequence of successive 2d rotations.
http://www.continuummechanics.org/rotationmatrix.html
args:
n : The dimensionality of the space in which we are going to rotate things.
import numpy as np
"""
https://math.stackexchange.com/questions/4660754/can-an-arbitrary-3-d-shape-be-fitted-inside-a-cube-so-it-touches-all-the-sides/4660761?noredirect=1#comment9845446_4660761
"""
def make_span_same(sq, r, ix1, ix2):
while abs(span(sq, ix1) - span(sq, ix2)) > 1e-2:
sq = np.dot(sq, r)
return sq
@ryu577
ryu577 / fft_3.py
Created December 29, 2022 21:01
Fast Fourier transform that works on inputs whose size is a power of 3
def fft_3(x):
"""
Perform a fast Fourier transform
on the given array of complex numbers.
The arrays size should be a power of 3.
"""
n = len(x)
if n == 1:
return x
# The complex roots of unity.
@ryu577
ryu577 / fft_2.py
Created December 28, 2022 21:56
Perform FFT on arrays of size that is a power of 2
import numpy as np
def fft_2(a):
"""
Perform a fast Fourier transform
on the array, a. The size of the array
has to be a power of 2. Otherwise, it will
yield incorrect results.
"""
n = len(a)
@ryu577
ryu577 / polynom_mult.py
Last active December 21, 2022 07:16
Multiplication of two polynomials given in coefficient form
def polynom_mult(a, b):
"""
Multiplies two polynomials given in coefficient form.
The input arrays a and b represent the coefficients.
"""
# The output polynomial initialized to
# an array of zeros.
c = [0]*(len(a)+len(b)-1)
# This double loop is the distributive law
import numpy as np
import networkx as nx
from PIL import Image, ImageDraw, ImageFont
#Coordinates of all the cities for plotting on a picture.
coord = {
'staging-1': (362, 47),
'staging-2': (908, 140),
'staging-3': (1130, 260),
ukr_grph_ts = {
'staging-1': {'chernihiv': 5},
'chernihiv': {'brovary': 4},
'brovary': {'kyiv': 1},
'boryspil': {'kyiv': 1.3, 'pereiaslav': 2.3},
'pereiaslav': {'boryspil': 3.3, 'kremenchuk': 2.5},
'kremenchuk': {'cherkasy': 2.3, 'pereiaslav': 3.1, 'poltava': 2.6, 'dnipro': 2.4, 'kropyvnytskyi': 2.0},
'cherkasy': {'kyiv': 3.2, 'kremenchuk': 2.2},
'bila_tserkva': {'kyiv': 3.1, 'uman': 2.5},
import numpy as np
from scipy.stats import norm, lognorm, expon, lomax, weibull_min
import matplotlib.pyplot as plt
def prcntl(a, q, interpolate=1):
a = sorted(a)
n = len(a)
lt = int(np.floor(q*(n-1)))
frac = 0