Skip to content

Instantly share code, notes, and snippets.

View WhiskersReneeWe's full-sized avatar
🎯
Focusing

Renee Liu WhiskersReneeWe

🎯
Focusing
View GitHub Profile
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:
# 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):
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()
@WhiskersReneeWe
WhiskersReneeWe / shrink_matrix.R
Created May 20, 2019 18:25
Shrink a 28 * 28 matrix to 14 * 14 in 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
@WhiskersReneeWe
WhiskersReneeWe / blockchain_linkedlist.py
Created May 20, 2019 18:21
Linked List implementation of a simple blockchain
# 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