@scurrlin/stencil 1.24.3 → 1.24.5

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 +11 -125
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -16,144 +16,30 @@ 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 212 "Word Search 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 214 "Shortest Palindrome":
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
-
51
26
  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)
27
+ def shortestPalindrome(self, s: str) -> str:
28
+ r = s[::-1]
29
+ for i in range(len(s) + 1):
30
+ if s.startswith(r[i:]):
31
+ return r[:i] + s
89
32
  ```
90
33
 
91
34
  Solution with Stencil
92
35
 
93
36
  ```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
-
119
37
  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)
38
+ d s(s, s: s) -> s:
39
+ r = s[::-1]
40
+ f i i r(l(s) + 1):
41
+ i s.s(r[i:]):
42
+ r r[:i] + s
157
43
  ```
158
44
 
159
45
  ## Local Installation
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@scurrlin/stencil",
3
- "version": "1.24.3",
3
+ "version": "1.24.5",
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": {