Skip to content

Instantly share code, notes, and snippets.

@cxrayana
cxrayana / HW4-P4.py
Created July 14, 2023 02:44
CS582-R342D927
from enum import Enum
from typing import List, NamedTuple
import random
class Cell(str, Enum):
EMPTY = " "
BLOCKED = "X"
START = "S"
GOAL = "G"
PATH = "*"
@cxrayana
cxrayana / HW4-P3.py
Created July 14, 2023 02:43
CS582-R342D927
from enum import Enum
from typing import List, NamedTuple
import random
class Cell(str, Enum):
EMPTY = " "
BLOCKED = "X"
START = "S"
GOAL = "G"
PATH = "*"
@cxrayana
cxrayana / HW4-P2.py
Created July 14, 2023 02:31
CS582-R342D927
from enum import Enum
from typing import List, NamedTuple
import random
class Cell(str, Enum):
EMPTY = " "
BLOCKED = "X"
START = "S"
GOAL = "G"
PATH = "*"
@cxrayana
cxrayana / HW4-P1.py
Created July 14, 2023 02:27
CS582-R342D927
from __future__ import annotations
from typing import TypeVar, Iterable, Sequence, Protocol, Any
T = TypeVar('T')
def linear_contains(iterable: Iterable[T], key: T) -> bool:
for item in iterable:
if item == key:
return True
return False
@cxrayana
cxrayana / HW3-P10.py
Created June 30, 2023 04:41
CS582-R342D927
def bubbleSort(lyst):
n = len(lyst)
while n > 1: # Do n - 1 bubbles
i = 1
while i < n:
if lyst[i] < lyst[i - 1]: # Exchange if needed
swap(lyst, i, i - 1)
i += 1
n -= 1
@cxrayana
cxrayana / HW3-P12.py
Created June 30, 2023 04:38
CS582-R342D927
def insertionSort(lyst):
i = 1
while i < len(lyst):
itemToInsert = lyst[i]
j = i - 1
while j >= 0:
if itemToInsert < lyst[j]:
lyst[j + 1] = lyst[j]
j -= 1
else:
@cxrayana
cxrayana / HW3-P11.py
Created June 30, 2023 04:34
CS582-R342D927
def bubbleSort(lyst):
n = len(lyst)
while n > 1: # Do n - 1 bubbles
i = 1
while i < n:
if lyst[i] < lyst[i - 1]: # Exchange if needed
swap(lyst, i, i - 1)
i += 1
n -= 1
@cxrayana
cxrayana / HW3-P9.py
Created June 30, 2023 04:28
CS582-R342D927
def selectionSort(lyst):
i = 0
while i < len(lyst) - 1:
minIndex = i
j = i + 1
while j < len(lyst): # Start a search
if lyst[j] < lyst[minIndex]:
minIndex = j
j += 1
if minIndex != i: # Exchange if needed
@cxrayana
cxrayana / HW3-P8.py
Created June 30, 2023 04:25
CS582-R342D927
def swap(lyst, i, j):
temp = lyst[i]
lyst[i] = lyst[j]
lyst[j] = temp
print(lyst)
lyst = [4,5,12,8]
print(lyst)
lyst = swap(lyst,2,3)
@cxrayana
cxrayana / HW3-P7.py
Created June 30, 2023 03:49
CS582-R342D927
class SavingsAccount(object):
def __init__(self, name, pin, balance = 0.0):
self._name = name
self._pin = pin
self._balance = balance
def __lt__(self, other):
return self._name < other._name
s1 = SavingsAccount("Ken", "1000", 0)