Skip to content

Instantly share code, notes, and snippets.

View sadrok's full-sized avatar
🐉

Francois Basson sadrok

🐉
View GitHub Profile
@sadrok
sadrok / tree_height.py
Created April 18, 2017 15:10
Tasked to find the height of a binary search tree - the getHeight() method is my solution
# NODE CLASS PROVIDED
class Node:
def __init__(self,data):
self.right=self.left=None
self.data = data
class Solution:
# INSERT METHOD PROVIDED
def insert(self,root,data):
if root==None:
@sadrok
sadrok / brackets.py
Last active May 30, 2020 15:12
Matching bracket problem - one of many solutions
"""
I found some problems with my initial solution including a huge
flaw in the final logic.
"""
BRACKETS = dict(['()', '{}', '[]', "<>"])
CLOSING_BRACKETS = set(BRACKETS.values())
def brackets(test_str):
bracket_stack = []
"""
anagram_1 was my initial naive approach to the simple anagram-check problem.
anagram_2 is a more compact version which should provide the same results.
However out of interests sake I ran timeit tests against both functions and got surprising results:
Testing anagram_1 against a small set of words resulted in about 21usec going over each loop
>python -m timeit -s "from anagram_test import test, anagram_1" -- "test(anagram_1)"
20000 loops, best of 5: 14.9 usec per loop
But anagram_2, the more compact version, was surprisingly slower!
const uint8_t numColumns = 5;
const uint8_t frames[16 * numColumns] PROGMEM = {
0x82, 0x7C, 0x7C, 0x7C, 0x82, // digit 0
0xFE, 0xBC, 0x00, 0xFC, 0xFE, // digit 1
0xB8, 0x74, 0x6C, 0x6C, 0x9C, // digit 2
0xBA, 0x7C, 0x6C, 0x6C, 0x92, // digit 3
0xE6, 0xD6, 0xB6, 0x00, 0xF6, // digit 4
0x1A, 0x6C, 0x6C, 0x6C, 0x72, // digit 5
0xC2, 0xAC, 0x6C, 0x6C, 0xF2, // digit 6
0x7E, 0x70, 0x6E, 0x5E, 0x3E, // digit 7