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
#!/usr/bin/env python3 | |
class Node(object): | |
"""Class for tree nodes""" | |
def __init__(self, key): | |
super(Node, self).__init__() | |
self.key = key | |
self.left = None |
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
#!/usr/bin/env python3 | |
""" | |
Sudoku Solver | |
guesses: | |
1-9 | |
grid: |
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
#!/usr/bin/env python3 | |
def is_safe(x, y, n, maze): | |
if 0 <= x <= n-1 and 0 <= y <= n - 1 and maze[y][x] == 1: | |
return True | |
else: | |
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
#!/usr/bin/env python3 | |
def is_safe(row, col, size, board): | |
# check vertical | |
for y in range(row): | |
if board[y][col]: | |
return False | |
# check left diagonal |
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
#!/usr/bin/env python3 | |
def memoization(function): | |
memo = {} | |
def helper(x): | |
if x not in memo: | |
memo[x] = function(x) | |
return memo[x] |
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
#!/usr/bin/env python3 | |
""" | |
Binary Indexed Tree / Fenwick Tree | |
https://www.hackerearth.com/practice/notes/binary-indexed-tree-made-easy-2/ | |
https://www.topcoder.com/community/data-science/data-science-tutorials/binary-indexed-trees/ | |
https://www.youtube.com/watch?v=v_wj_mOAlig | |
https://www.youtube.com/watch?v=kPaJfAUwViY | |
""" |
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
import math | |
class Point(object): | |
'''Creates a point on a coordinate plane with values x and y''' | |
def __init__(self, x, y): | |
'''Defines the x and y coordinates in the variables''' | |
self.X = x | |
self.Y = y |
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
#!/usr/bin/env python3 | |
def tower_of_hanoi(number, beginning, auxiliary, ending): | |
if number == 1: | |
print("{} -> {}".format(beginning, ending)) | |
return | |
else: | |
tower_of_hanoi(number-1, beginning, ending, auxiliary) |
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
#!/usr/bin/env python3 | |
from itertools import permutations | |
def main(): | |
t = int(input()) | |
for cases in range(t): | |
string = str(input()) |
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
""" | |
Snake Eater | |
Made with PyGame | |
""" | |
import pygame, sys, time, random | |
# Difficulty settings | |
# Easy -> 10 |