This file contains 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
# coding=utf-8 | |
"""Sudoku solver using constraint propogation + search""" | |
from collections import defaultdict | |
from itertools import chain, product | |
from pprint import pprint | |
from typing import List | |
CELLS = None | |
UNITS = None | |
PEERS = None |
This file contains 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 Solution: | |
def setZeroes(self, matrix): | |
""" | |
:type matrix: List[List[int]] | |
:rtype: void Do not return anything, modify matrix in-place instead. | |
""" | |
row_0 = col_0 = False | |
# step 1: iterate through matrix and set 0 markers in 1st row and col (except top left) | |
for row_idx, row in enumerate(matrix): | |
for col_idx, val in enumerate(row): |
This file contains 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 detect_cycles(graph: dict) -> bool: | |
"""Return whether or not graph has any cycles.""" | |
visited = set() | |
path = set() | |
def visit(node): | |
"""Return True if node is in a cycle""" | |
if node in visited: | |
return False | |
visited.add(node) |
This file contains 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 Node: | |
def __init__(self, val, left=None, right=None): | |
self.val = val | |
self.left = left | |
self.right = right | |
def is_bst_rec(node: Node, min_v: object = None, max_v: object = None) -> bool: # todo should use float('inf') and float('-inf') | |
if (min_v and node.val < min_v) or (max_v and node.val > max_v): | |
return False |
This file contains 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
""" | |
EXAMPLES | |
Puzzle 1: | |
[0, 1, 4] | |
[2, 3, 5] | |
[8, 7, 6] | |
Longest chain is [4, 5, 6, 7, 8] with length 5. | |
Puzzle 2: | |
[0, 2] |
This file contains 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
import random | |
if __name__ == "__main__": | |
# define and initialize queue variables | |
lambd_in = 0.5 | |
lambd_out = 0.4 | |
closing_time = 100 | |
t = 0 | |
num_arrivals = 0 | |
num_departures = 0 |
This file contains 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
import random | |
import numpy as np | |
# for graphing | |
from mpl_toolkits.mplot3d.axes3d import Axes3D | |
import matplotlib.pyplot as plt | |
if __name__ == "__main__": | |
# setting up scatterplot | |
Xa = [] | |
Ya = [] |
This file contains 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
# 8 Tile Solver | |
# Written by Daniel Ong for COEN 166: Artificial Intelligence | |
# | |
# A comparison of the real time taken to solve an n tile puzzle using: | |
# 1. Iterative deepening depth-first search | |
# 2. Depth-first search | |
# 3. Breadth-first search | |
# Tested on the 8 tile puzzle | |
# Some code adapted from Edd Mann's blog post: http://eddmann.com/posts/using-iterative-deepening-depth-first-search-in-python/ |
This file contains 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
TEMPLATE = app | |
CONFIG += console | |
CONFIG -= app_bundle | |
CONFIG -= qt | |
SOURCES += main.cpp \ | |
polygon.cpp | |
HEADERS += \ | |
vertex.h \ |