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
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: |
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
# 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): |
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 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() |
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
# 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 |
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
# 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 |