Skip to content

Instantly share code, notes, and snippets.

View codeboy101's full-sized avatar

Tushar codeboy101

View GitHub Profile
def quicksort(A, lo, hi):
if lo < hi:
p = partition(A, lo, hi)
quicksort(A, lo, p-1)
quicksort(A, p+1, hi)
def partition(A, lo, hi):
pivot = A[hi]
i = lo - 1
for j in range(lo, hi):
import random
import time
from search import *
from utils import *
from string import ascii_lowercase
def vowel_count(word):
return sum(word.count(i) for i in 'aeiou')
def mate(p1, p2):
class Node(object):
def __init__(self, value, connected=None):
self.value = value
if connected:
self.connected = [node for node in connected]
else:
self.connected = []
def add_connection(self, node):
if isinstance(node, Node):
class Queue:
"""Queue is an abstract class/interface. There are three types:
Stack(): A Last In First Out Queue.
FIFOQueue(): A First In First Out Queue.
PriorityQueue(order, f): Queue in sorted order (default min-first).
Each type supports the following methods and functions:
q.append(item) -- add an item to the queue
q.extend(items) -- equivalent to: for item in items: q.append(item)
q.pop() -- return the top item from the queue
class FIFOQueue(Queue):
"""A First-In-First-Out Queue."""
def __init__(self):
self.A = []
self.start = 0
def append(self, item):
self.A.append(item)
import random
from search import *
class Node(object):
def __init__(self, label, state):
self.label = label
self.state = state
class Game(object):
def __init__(self, start, goal):
import time
import random
from itertools import permutations
class ModelBasedAgent():
def __init__(self, shape, dirt_patches):
self.rows = shape[0]
self.cols = shape[1]
self.size = self.rows * self.cols
self.environment = ['' for i in range(self.size)]
class Node():
def __init__(self, label, value, parent):
self.parent = parent
self.child = []
self.label = label
self.value = value
def get_child(self):
return self.child
import numpy as np
import pandas as pd
import time
from tree import Node
test_df = pd.read_csv('cars.txt', names=['buying', 'maint', 'doors', 'persons', 'lug_boot', 'safety', 'result'])
test_df.drop(['doors', 'persons', 'safety'], axis=1, inplace=True)
test_df['result'] = test_df['result'].map({'unacc':'notbuy', 'acc':'buy', 'vgood':'buy', 'good':'notbuy'})
df = test_df
backup_df = df
class Vector():
def __init__(self, vector):
self.vector = vector
def __add__(self, vector2):
result = Vector([])
if isinstance(vector2, int):
for i in range(len(self.vector)):
result.append(self.vector[i] + vector2)
return result