@scurrlin/stencil 1.24.1 → 1.24.3

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 +125 -55
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -16,74 +16,144 @@ 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 210 "Course Schedule II":
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 212 "Word Search II":
20
20
 
21
21
  ## Example
22
22
 
23
23
  Solution
24
24
 
25
25
  ```python
26
+ class TrieNode:
27
+ def __init__(self):
28
+ self.children = {}
29
+ self.isWord = False
30
+ self.refs = 0
31
+
32
+ def addWord(self, word):
33
+ cur = self
34
+ cur.refs += 1
35
+ for c in word:
36
+ if c not in cur.children:
37
+ cur.children[c] = TrieNode()
38
+ cur = cur.children[c]
39
+ cur.refs += 1
40
+ cur.isWord = True
41
+
42
+ def removeWord(self, word):
43
+ cur = self
44
+ cur.refs -= 1
45
+ for c in word:
46
+ if c in cur.children:
47
+ cur = cur.children[c]
48
+ cur.refs -= 1
49
+
50
+
26
51
  class Solution:
27
- def findOrder(self, numCourses: int, prerequisites: List[List[int]]) -> List[int]:
28
- prereq = {c: [] for c in range(numCourses)}
29
-
30
- for crs, pre in prerequisites:
31
- prereq[crs].append(pre)
32
-
33
- output = []
34
- visit, cycle = set(), set()
35
-
36
- def dfs(crs):
37
- if crs in cycle:
38
- return False
39
- if crs in visit:
40
- return True
41
- cycle.add(crs)
42
- for pre in prereq[crs]:
43
- if dfs(pre) == False:
44
- return False
45
- cycle.remove(crs)
46
- visit.add(crs)
47
- output.append(crs)
48
- return True
49
-
50
- for c in range(numCourses):
51
- if dfs(c) == False:
52
- return []
53
- return output
52
+ def findWords(self, board: List[List[str]], words: List[str]) -> List[str]:
53
+ root = TrieNode()
54
+ for w in words:
55
+ root.addWord(w)
56
+
57
+ ROWS, COLS = len(board), len(board[0])
58
+ res, visit = set(), set()
59
+
60
+ def dfs(r, c, node, word):
61
+ if (
62
+ r not in range(ROWS)
63
+ or c not in range(COLS)
64
+ or board[r][c] not in node.children
65
+ or node.children[board[r][c]].refs < 1
66
+ or (r, c) in visit
67
+ ):
68
+ return
69
+
70
+ visit.add((r, c))
71
+ node = node.children[board[r][c]]
72
+ word += board[r][c]
73
+ if node.isWord:
74
+ node.isWord = False
75
+ res.add(word)
76
+ root.removeWord(word)
77
+
78
+ dfs(r + 1, c, node, word)
79
+ dfs(r - 1, c, node, word)
80
+ dfs(r, c + 1, node, word)
81
+ dfs(r, c - 1, node, word)
82
+ visit.remove((r, c))
83
+
84
+ for r in range(ROWS):
85
+ for c in range(COLS):
86
+ dfs(r, c, root, "")
87
+
88
+ return list(res)
54
89
  ```
55
90
 
56
91
  Solution with Stencil
57
92
 
58
93
  ```python
94
+ c T:
95
+ d __i__(s):
96
+ s.c = {}
97
+ s.i = F
98
+ s.r = 0
99
+
100
+ d a(s, w):
101
+ c = s
102
+ c.r += 1
103
+ f c i w:
104
+ i c n i c.c:
105
+ c.c[c] = T()
106
+ c = c.c[c]
107
+ c.r += 1
108
+ c.i = T
109
+
110
+ d r(s, w):
111
+ c = s
112
+ c.r -= 1
113
+ f c i w:
114
+ i c i c.c:
115
+ c = c.c[c]
116
+ c.r -= 1
117
+
118
+
59
119
  c S:
60
- d f(s, n: i, p: L[L[i]]) -> L[i]:
61
- p = {c: [] f c i r(n)}
62
-
63
- f c, p i p:
64
- p[c].a(p)
65
-
66
- o = []
67
- v, c = s(), s()
68
-
69
- d d(c):
70
- i c i c:
71
- r F
72
- i c i v:
73
- r T
74
- c.a(c)
75
- f p i p[c]:
76
- i d(p) == F:
77
- r F
78
- c.r(c)
79
- v.a(c)
80
- o.a(c)
81
- r T
82
-
83
- f c i r(n):
84
- i d(c) == F:
85
- r []
86
- r o
120
+ d f(s, b: L[L[s]], w: L[s]) -> L[s]:
121
+ r = T()
122
+ f w i w:
123
+ r.a(w)
124
+
125
+ R, C = l(b), l(b[0])
126
+ r, v = s(), s()
127
+
128
+ d d(r, c, n, w):
129
+ i (
130
+ r n i r(R)
131
+ o c n i r(C)
132
+ o b[r][c] n i n.c
133
+ o n.c[b[r][c]].r < 1
134
+ o (r, c) i v
135
+ ):
136
+ r
137
+
138
+ v.a((r, c))
139
+ n = n.c[b[r][c]]
140
+ w += b[r][c]
141
+ i n.i:
142
+ n.i = F
143
+ r.a(w)
144
+ r.r(w)
145
+
146
+ d(r + 1, c, n, w)
147
+ d(r - 1, c, n, w)
148
+ d(r, c + 1, n, w)
149
+ d(r, c - 1, n, w)
150
+ v.r((r, c))
151
+
152
+ f r i r(R):
153
+ f c i r(C):
154
+ d(r, c, r, "")
155
+
156
+ r l(r)
87
157
  ```
88
158
 
89
159
  ## Local Installation
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@scurrlin/stencil",
3
- "version": "1.24.1",
3
+ "version": "1.24.3",
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": {