View sol_to_last_challenge.py
t = "57888888882339999" | |
str1 = "6539923335" | |
str4 = '234253876334' | |
def is_NumberStream(str): | |
import re | |
for i in t: | |
pattern = i * int(i) | |
if re.search(pattern, str): | |
return True | |
else: |
View RouteTrie_implementation.py
# A RouteTrieNode will be similar to our autocomplete TrieNode... with one additional element, a handler. | |
class RouteTrieNode(object): | |
def __init__(self, handler = 'root handler', default_handler = 'not found handler'): | |
# Initialize the node with children as before, plus a handler | |
self.children = {} | |
self.handler = handler | |
self.default_handler = default_handler | |
def insert(self, part, part_handler): |
View gist:072d057163178f7af66b1d424abb0634
class TrieNode: | |
def __init__(self): | |
## Initialize this node in the Trie | |
self.children = {} | |
self.is_word = False | |
def insert(self, char): | |
## Add a child node in this Trie | |
if char not in self.children: | |
self.children[char] = TrieNode() |
View shrink_matrix.R
# Divide each 28*28 image into 2*2 non-overlapping blocks. | |
shrink_img <- function(img){ | |
# input: 28 * 28 image | |
# window size is 2 * 2, move horizontally -- fix row first, move across columns | |
# output: 14 * 14 image | |
shrinked_img = matrix(, nrow = 14, ncol = 14) | |
for (i in c(0:13)) { | |
for (j in c(0:13)){ | |
row = 1 + 2 * i |
View blockchain_linkedlist.py
# blockchain implementation using Linked List | |
# Copyright: Renee S. Liu | |
# First is the information hash | |
# We do this for the information we want to store in the block chain | |
# such as transaction time, data, and information like the previous chain. | |
import hashlib | |
import datetime as date | |
# The next main component is the block class |