@scurrlin/stencil 1.5.3 → 1.5.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 +25 -91
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -14,114 +14,48 @@ Whether you are studying for technical interviews, or just starting your coding
14
14
 
15
15
  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.
16
16
 
17
- 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 30 "Substring with Concatenation of All Words":
17
+ 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 32 "Longest Valid Parentheses":
18
18
 
19
19
  ## Example
20
20
 
21
21
  Solution
22
22
 
23
23
  ```python
24
- from collections import defaultdict
25
- from typing import List
26
-
27
24
  class Solution:
28
- def findSubstring(self, s: str, words: List[str]) -> List[int]:
29
- if not s or not words:
30
- return []
31
-
32
- word_len = len(words[0])
33
- count_words = len(words)
34
- total_len = word_len * count_words
35
-
36
- if len(s) < total_len:
37
- return []
38
- word_count = defaultdict(int)
39
- for w in words:
40
- word_count[w] += 1
41
- result = []
25
+ def longestValidParentheses(self, s: str) -> int:
26
+ max_len = 0
27
+ stack = [-1]
42
28
 
43
- for start_offset in range(word_len):
44
- left = start_offset
45
- matched_words = 0
46
- seen_count = defaultdict(int)
47
- for right in range(start_offset, len(s), word_len):
48
- current_word = s[right : right + word_len]
49
- if current_word in word_count:
50
- seen_count[current_word] += 1
51
- if seen_count[current_word] <= word_count[current_word]:
52
- matched_words += 1
53
- else:
54
- while seen_count[current_word] > word_count[current_word]:
55
- left_word = s[left : left + word_len]
56
- seen_count[left_word] -= 1
57
- if seen_count[left_word] < word_count[left_word]:
58
- matched_words -= 1
59
- left += word_len
60
- if matched_words == count_words:
61
- result.append(left)
62
- left_word = s[left : left + word_len]
63
- seen_count[left_word] -= 1
64
- if seen_count[left_word] < word_count[left_word]:
65
- matched_words -= 1
66
- left += word_len
29
+ for i, char in enumerate(s):
30
+ if char == '(':
31
+ stack.append(i)
32
+ else:
33
+ stack.pop()
34
+ if not stack:
35
+ stack.append(i)
67
36
  else:
68
- seen_count.clear()
69
- matched_words = 0
70
- left = right + word_len
71
- return result
37
+ max_len = max(max_len, i - stack[-1])
38
+ return max_len
72
39
  ```
73
40
 
74
41
  Solution with Stencil
75
42
 
76
43
  ```python
77
- f c i d
78
- f t i L
79
-
80
44
  c S:
81
- d f(s, s: s, w: L[s]) -> L[i]:
82
- i n s o n w:
83
- r []
84
-
85
- w_l = l(w[0])
86
- c_w = l(w)
87
- t_l = w_l * c_w
88
-
89
- i l(s) < t_l:
90
- r []
91
- w_c = d(i)
92
- f w i w:
93
- w_c[w] += 1
94
- r = []
45
+ d l(s, s: s) -> i:
46
+ m_l = 0
47
+ s = [-1]
95
48
 
96
- f s_o i r(w_l):
97
- l = s_o
98
- m_w = 0
99
- s_c = d(i)
100
- f r i r(s_o, l(s), w_l):
101
- c_w = s[r : r + w_l]
102
- i c_w i w_c:
103
- s_c[c_w] += 1
104
- i s_c[c_w] <= w_c[c_w]:
105
- m_w += 1
106
- e:
107
- w s_c[c_w] > w_c[c_w]:
108
- l_w = s[l : l + w_l]
109
- s_c[l_w] -= 1
110
- i s_c[l_w] < w_c[l_w]:
111
- m_w -= 1
112
- l += w_l
113
- i m_w == c_w:
114
- r.a(l)
115
- l_w = s[l : l + w_l]
116
- s_c[l_w] -= 1
117
- i s_c[l_w] < w_c[l_w]:
118
- m_w -= 1
119
- l += w_l
49
+ f i, c i e(s):
50
+ i c == '(':
51
+ s.a(i)
52
+ e:
53
+ s.p()
54
+ i n s:
55
+ s.a(i)
120
56
  e:
121
- s_c.c()
122
- m_w = 0
123
- l = r + w_l
124
- r r
57
+ m_l = m(m_l, i - s[-1])
58
+ r m_l
125
59
  ```
126
60
 
127
61
  ## Local Installation
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@scurrlin/stencil",
3
- "version": "1.5.3",
3
+ "version": "1.5.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": {