@scurrlin/stencil 1.24.2 → 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 +116 -52
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -16,7 +16,7 @@ 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 211 "Design Add and Search Words Data Structure":
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
 
@@ -26,34 +26,66 @@ Solution
26
26
  class TrieNode:
27
27
  def __init__(self):
28
28
  self.children = {}
29
- self.is_word = False
30
-
31
- class WordDictionary:
32
- def __init__(self):
33
- self.root = TrieNode()
29
+ self.isWord = False
30
+ self.refs = 0
34
31
 
35
32
  def addWord(self, word):
36
- current_node = self.root
37
- for character in word:
38
- current_node = current_node.children.setdefault(character, TrieNode())
39
- current_node.is_word = True
40
-
41
- def search(self, word):
42
- def dfs(node, index):
43
- if index == len(word):
44
- return node.is_word
45
-
46
- if word[index] == ".":
47
- for child in node.children.values():
48
- if dfs(child, index+1):
49
- return True
50
-
51
- if word[index] in node.children:
52
- return dfs(node.children[word[index]], index+1)
53
-
54
- return False
55
-
56
- return dfs(self.root, 0)
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
+
51
+ class Solution:
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)
57
89
  ```
58
90
 
59
91
  Solution with Stencil
@@ -62,34 +94,66 @@ Solution with Stencil
62
94
  c T:
63
95
  d __i__(s):
64
96
  s.c = {}
65
- s.i_w = F
66
-
67
- c W:
68
- d __i__(s):
69
- s.r = T()
97
+ s.i = F
98
+ s.r = 0
70
99
 
71
100
  d a(s, w):
72
- c_n = s.r
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
73
113
  f c i w:
74
- c_n = c_n.c.s(c, T())
75
- c_n.i_w = T
76
-
77
- d s(s, w):
78
- d d(n, i):
79
- i i == l(w):
80
- r n.i_w
81
-
82
- i w[i] == ".":
83
- f c i n.c.v():
84
- i d(c, i+1):
85
- r T
86
-
87
- i w[i] i n.c:
88
- r d(n.c[w[i]], i+1)
89
-
90
- r F
91
-
92
- r d(s.r, 0)
114
+ i c i c.c:
115
+ c = c.c[c]
116
+ c.r -= 1
117
+
118
+
119
+ c S:
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)
93
157
  ```
94
158
 
95
159
  ## Local Installation
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@scurrlin/stencil",
3
- "version": "1.24.2",
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": {