Skip to content

Instantly share code, notes, and snippets.

View syphh's full-sized avatar

Syphax Ait oubelli syphh

View GitHub Profile
import numpy as np
import matplotlib.pyplot as plt
def midpoint(p1, p2):
x1, y1 = p1
x2, y2 = p2
return (x1+x2)/2, (y1+y2)/2
import numpy as np
def approximate_pi(n):
points = np.random.uniform(-1, 1, (n, 2))
inside = np.sum(points[:,0]**2+points[:,1]**2 <= 1)
k = inside/n
return 4*k
n = 1000000
from typing import List, Any
class Node:
def __init__(self, key, value, nxt=None):
self.key: str = key
self.value: Any = value
self.nxt: Node = nxt
class LinkedList:
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
def update_annot(ind):
pos = sc.get_offsets()[ind["ind"][0]]
annot.xy = pos
attributes_to_show = [0, 1, 2, 7]
text = df.iloc[ind["ind"][0], attributes_to_show].to_string()
# 1st approach:
def kth_largest(arr, k):
for i in range(k-1):
arr.remove(max(arr))
return max(arr)
# 2nd approach:
def kth_largest(arr, k):
n = len(arr)
@syphh
syphh / bus_park_optimization.py
Created December 5, 2023 12:52
Minimize total distance between drivers and their assigned bus station given capacity constraints
import pulp
import pandas as pd
import numpy as np
"""Example drivers.csv file:
driver_id,lat,lon
dr_1,10,20
dr_2,30,50
dr_3,50,40
dr_4,80,20