Skip to content

Instantly share code, notes, and snippets.

View theabbie's full-sized avatar
❤️
Playing With Life Since 2002

Abhishek Choudhary theabbie

❤️
Playing With Life Since 2002
View GitHub Profile
@theabbie
theabbie / Dijkstra.c
Last active April 15, 2024 02:27
Dijkstra's Shortest path algorithm in C
#include <stdio.h>
#define MAX 20
#define INF 1000
typedef struct {
int predecessor;
int distance;
int status;
int neighbours[MAX];
} Node;
@theabbie
theabbie / RandomGraphGenerator.py
Created January 24, 2024 05:09
Random Graph Generator
from random import *
# Floyd Sampler
def sampler(N, K):
res = set()
for i in range(N - K, N):
j = randint(0, i)
if j not in res:
res.add(j)
else:
@theabbie
theabbie / RandomTreeGenerator.py
Created January 23, 2024 11:02
Random Tree Generator
from random import *
def randTree(N):
edges = []
comps = [[i] for i in range(N)]
for _ in range(N - 1):
i = randint(0, len(comps) - 1)
j = randint(0, len(comps) - 2)
if j == i:
j += 1
@theabbie
theabbie / lights_out.md
Last active October 6, 2023 10:49
Python Script to solve "Lights Out" Game in optimal way using BFS.
@theabbie
theabbie / iterative_merge_sort.py
Created September 6, 2023 09:36
Iterative Merge Sort in Python
def merge(arr, i, mid, j, extra):
x = i
y = mid
while x < mid and y < j:
if arr[x] <= arr[y]:
extra[x + y - mid] = arr[x]
x += 1
else:
extra[x + y - mid] = arr[y]
y += 1
@theabbie
theabbie / leetcode.txt
Created February 21, 2023 12:42
All Leetcode Questions
1 two-sum
2 add-two-numbers
3 longest-substring-without-repeating-characters
4 median-of-two-sorted-arrays
5 longest-palindromic-substring
6 zigzag-conversion
7 reverse-integer
8 string-to-integer-atoi
9 palindrome-number
10 regular-expression-matching
@theabbie
theabbie / filepicker.js
Created December 24, 2020 16:24
Promise-based File Picker in Javascript
// opens file dialog waits till user selects file and return dataurl of uploaded file
async function pick() {
var filepicker = document.createElement("input");
filepicker.setAttribute("type","file");
filepicker.click();
return new Promise((resolve,reject) => {
filepicker.addEventListener("change", e => {
var reader = new FileReader();
reader.addEventListener('load', file => resolve(file.target.result));
@theabbie
theabbie / ascii_human.py
Last active October 22, 2022 08:12
Dancing ASCII Human in Python
import random
from time import sleep
class Human:
def __init__(self):
self.human = [[" ", "o", " "], ["/", "|", "\\"], ["/", " ", "\\"]]
self.front = False
self.commandmap = {
"left hand to head": self.leftHandToHead,
"left hand to hip": self.leftHandToHip,
@theabbie
theabbie / rle.py
Created October 15, 2022 19:16
Run-length Encoding Imlementation in Python
def encode(s):
n = len(s)
res = []
i = 0
while i < n:
ctr = 1
while i < n - 1 and s[i] == s[i + 1]:
ctr += 1
i += 1
if ctr == 1: