@scurrlin/stencil 1.18.4 → 1.18.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 +41 -31
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -16,48 +16,58 @@ 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 145 "Binary Tree Postorder Traversal":
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 146 "LRU Cache":
20
20
 
21
21
  ## Example
22
22
 
23
23
  Solution
24
24
 
25
25
  ```python
26
- class Solution:
27
- def postorderTraversal(self, root: Optional[TreeNode]) -> List[int]:
28
- if root is None:
29
- return []
30
-
31
- stack, result = [root], []
32
- while stack:
33
- node = stack.pop()
34
- result.append(node.val)
35
- if node.left:
36
- stack.append(node.left)
37
- if node.right:
38
- stack.append(node.right)
39
- result.reverse()
40
- return result
26
+ import collections
27
+
28
+ class LRUCache:
29
+
30
+ def __init__(self, capacity: int):
31
+ self.capacity = capacity
32
+ self.dic = collections.OrderedDict()
33
+
34
+ def get(self, key: int) -> int:
35
+ if key not in self.dic:
36
+ return -1
37
+ self.dic.move_to_end(key)
38
+ return self.dic[key]
39
+
40
+ def put(self, key: int, value: int) -> None:
41
+ if key in self.dic:
42
+ self.dic.move_to_end(key)
43
+ self.dic[key] = value
44
+ if len(self.dic) > self.capacity:
45
+ self.dic.popitem(False)
41
46
  ```
42
47
 
43
48
  Solution with Stencil
44
49
 
45
50
  ```python
46
- c S:
47
- d p(s, r: O[T]) -> L[i]:
48
- i r i N:
49
- r []
50
-
51
- s, r = [r], []
52
- w s:
53
- n = s.p()
54
- r.a(n.v)
55
- i n.l:
56
- s.a(n.l)
57
- i n.r:
58
- s.a(n.r)
59
- r.r()
60
- r r
51
+ i c
52
+
53
+ c L:
54
+
55
+ d __i__(s, c: i):
56
+ s.c = c
57
+ s.d = c.O()
58
+
59
+ d g(s, k: i) -> i:
60
+ i k n i s.d:
61
+ r -1
62
+ s.d.m_t_e(k)
63
+ r s.d[k]
64
+
65
+ d p(s, k: i, v: i) -> N:
66
+ i k i s.d:
67
+ s.d.m_t_e(k)
68
+ s.d[k] = v
69
+ i l(s.d) > s.c:
70
+ s.d.p(F)
61
71
  ```
62
72
 
63
73
  ## Local Installation
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@scurrlin/stencil",
3
- "version": "1.18.4",
3
+ "version": "1.18.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": {