@scurrlin/stencil 1.23.8 → 1.23.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/README.md +59 -41
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -16,69 +16,87 @@ Whether you are studying for technical interviews, or just starting your coding
16
16
 
17
17
  Most people when they attempt to memorize something study the full text and then attempt to regurgitate it on a blank page. Shocking, I know... but what if there was a step in between? What if memorization and pattern recognition weren't all or nothing games? This is where Stencil comes in.
18
18
 
19
- Stencil is a language-agnostic memorization tool that strips code files down to their first letters while preserving spacing, capitalization, and punctuation. The "stencil" of the file is designed to act as a bridge between having something partially memorized and fully memorized. Below is an example of Stencil in action using LeetCode problem 207 "Course Schedule":
19
+ Stencil is a language-agnostic memorization tool that strips code files down to their first letters while preserving spacing, capitalization, and punctuation. The "stencil" of the file is designed to act as a bridge between having something partially memorized and fully memorized. Below is an example of Stencil in action using LeetCode problem 208 "Implement Trie (Prefix Tree)":
20
20
 
21
21
  ## Example
22
22
 
23
23
  Solution
24
24
 
25
25
  ```python
26
- class Solution:
27
- def canFinish(self, numCourses: int, prerequisites: List[List[int]]) -> bool:
28
- preMap = {i: [] for i in range(numCourses)}
26
+ class Trie:
29
27
 
30
- for crs, pre in prerequisites:
31
- preMap[crs].append(pre)
28
+ def __init__(self):
29
+ self.root = {}
32
30
 
33
- visiting = set()
34
-
35
- def dfs(crs):
36
- if crs in visiting:
31
+ def insert(self, word: str) -> None:
32
+
33
+ curr = self.root
34
+
35
+ for letter in word:
36
+ if letter not in curr:
37
+ curr[letter] = {}
38
+ curr = curr[letter]
39
+
40
+ curr['*'] = ''
41
+
42
+ def search(self, word: str) -> bool:
43
+
44
+ curr = self.root
45
+ for letter in word:
46
+ if letter not in curr:
37
47
  return False
38
- if preMap[crs] == []:
39
- return True
40
- visiting.add(crs)
41
- for pre in preMap[crs]:
42
- if not dfs(pre):
43
- return False
44
- visiting.remove(crs)
45
- preMap[crs] = []
46
- return True
48
+ curr = curr[letter]
49
+
50
+ return '*' in curr
47
51
 
48
- for c in range(numCourses):
49
- if not dfs(c):
52
+ def startsWith(self, prefix: str) -> bool:
53
+
54
+ curr = self.root
55
+ for letter in prefix:
56
+ if letter not in curr:
50
57
  return False
58
+ curr = curr[letter]
59
+
51
60
  return True
52
61
  ```
53
62
 
54
63
  Solution with Stencil
55
64
 
56
65
  ```python
57
- c S:
58
- d c(s, n: i, p: L[L[i]]) -> b:
59
- p = {i: [] f i i r(n)}
66
+ c T:
60
67
 
61
- f c, p i p:
62
- p[c].a(p)
68
+ d __i__(s):
69
+ s.r = {}
63
70
 
64
- v = s()
65
-
66
- d d(c):
67
- i c i v:
71
+ d i(s, w: s) -> N:
72
+
73
+ c = s.r
74
+
75
+ f l i w:
76
+ i l n i c:
77
+ c[l] = {}
78
+ c = c[l]
79
+
80
+ c['*'] = ''
81
+
82
+ d s(s, w: s) -> b:
83
+
84
+ c = s.r
85
+ f l i w:
86
+ i l n i c:
68
87
  r F
69
- i p[c] == []:
70
- r T
71
- v.a(c)
72
- f p i p[c]:
73
- i n d(p):
74
- r F
75
- v.r(c)
76
- p[c] = []
77
- r T
88
+ c = c[l]
89
+
90
+ r '*' i c
78
91
 
79
- f c i r(n):
80
- i n d(c):
92
+ d s(s, p: s) -> b:
93
+
94
+ c = s.r
95
+ f l i p:
96
+ i l n i c:
81
97
  r F
98
+ c = c[l]
99
+
82
100
  r T
83
101
  ```
84
102
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@scurrlin/stencil",
3
- "version": "1.23.8",
3
+ "version": "1.23.9",
4
4
  "description": "A memorization tool that strips code down to first letters and punctuation only.",
5
5
  "main": "src/index.js",
6
6
  "bin": {