@scurrlin/stencil 1.23.9 → 1.24.1
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.
- package/README.md +49 -63
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -16,88 +16,74 @@ 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
|
|
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":
|
|
20
20
|
|
|
21
21
|
## Example
|
|
22
22
|
|
|
23
23
|
Solution
|
|
24
24
|
|
|
25
25
|
```python
|
|
26
|
-
class
|
|
26
|
+
class Solution:
|
|
27
|
+
def findOrder(self, numCourses: int, prerequisites: List[List[int]]) -> List[int]:
|
|
28
|
+
prereq = {c: [] for c in range(numCourses)}
|
|
27
29
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
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:
|
|
30
|
+
for crs, pre in prerequisites:
|
|
31
|
+
prereq[crs].append(pre)
|
|
43
32
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
if letter not in curr:
|
|
47
|
-
return False
|
|
48
|
-
curr = curr[letter]
|
|
49
|
-
|
|
50
|
-
return '*' in curr
|
|
33
|
+
output = []
|
|
34
|
+
visit, cycle = set(), set()
|
|
51
35
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
curr = self.root
|
|
55
|
-
for letter in prefix:
|
|
56
|
-
if letter not in curr:
|
|
36
|
+
def dfs(crs):
|
|
37
|
+
if crs in cycle:
|
|
57
38
|
return False
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
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
|
|
61
54
|
```
|
|
62
55
|
|
|
63
56
|
Solution with Stencil
|
|
64
57
|
|
|
65
58
|
```python
|
|
66
|
-
c
|
|
59
|
+
c S:
|
|
60
|
+
d f(s, n: i, p: L[L[i]]) -> L[i]:
|
|
61
|
+
p = {c: [] f c i r(n)}
|
|
67
62
|
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
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:
|
|
63
|
+
f c, p i p:
|
|
64
|
+
p[c].a(p)
|
|
83
65
|
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
i l n i c:
|
|
87
|
-
r F
|
|
88
|
-
c = c[l]
|
|
89
|
-
|
|
90
|
-
r '*' i c
|
|
66
|
+
o = []
|
|
67
|
+
v, c = s(), s()
|
|
91
68
|
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
c = s.r
|
|
95
|
-
f l i p:
|
|
96
|
-
i l n i c:
|
|
69
|
+
d d(c):
|
|
70
|
+
i c i c:
|
|
97
71
|
r F
|
|
98
|
-
c
|
|
99
|
-
|
|
100
|
-
|
|
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
|
|
101
87
|
```
|
|
102
88
|
|
|
103
89
|
## Local Installation
|