This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from enum import Enum | |
from typing import List, NamedTuple | |
import random | |
class Cell(str, Enum): | |
EMPTY = " " | |
BLOCKED = "X" | |
START = "S" | |
GOAL = "G" | |
PATH = "*" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from enum import Enum | |
from typing import List, NamedTuple | |
import random | |
class Cell(str, Enum): | |
EMPTY = " " | |
BLOCKED = "X" | |
START = "S" | |
GOAL = "G" | |
PATH = "*" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from enum import Enum | |
from typing import List, NamedTuple | |
import random | |
class Cell(str, Enum): | |
EMPTY = " " | |
BLOCKED = "X" | |
START = "S" | |
GOAL = "G" | |
PATH = "*" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |