about summary refs log tree commit diff stats
path: root/graphviz.tlv
diff options
context:
space:
mode:
Diffstat (limited to 'graphviz.tlv')
-rw-r--r--graphviz.tlv50
1 files changed, 50 insertions, 0 deletions
diff --git a/graphviz.tlv b/graphviz.tlv
index 18fb7e0..bed0808 100644
--- a/graphviz.tlv
+++ b/graphviz.tlv
@@ -381,6 +381,56 @@
     >  append(target, src)
     >end
 - __teliva_timestamp: original
+  mfactorial:
+    >-- memoized version of factorial
+    >-- doesn't memoize recursive calls, but may be good enough
+    >mfactorial = memo1(factorial)
+- __teliva_timestamp: original
+  factorial:
+    >function factorial(n)
+    >  local result = 1
+    >  for i=1,n do
+    >    result = result*i
+    >  end
+    >  return result
+    >end
+- __teliva_timestamp: original
+  memo1:
+    >-- a higher-order function that takes a function of a single arg
+    >-- (that never returns nil)
+    >-- and returns a memoized version of it
+    >function memo1(f)
+    >  local memo = {}
+    >  return function(x)
+    >    if memo[x] == nil then
+    >      memo[x] = f(x)
+    >    end
+    >    return memo[x]
+    >  end
+    >end
+    >
+    >-- mfactorial doesn't seem noticeably faster
+    >function test_memo1()
+    >  for i=0,30 do
+    >    check_eq(mfactorial(i), factorial(i), 'memo1 over factorial: '..str(i))
+    >  end
+    >end
+- __teliva_timestamp: original
+  num_permutations:
+    >-- number of permutations of n distinct objects, taken r at a time
+    >function num_permutations(n, r)
+    >  return factorial(n)/factorial(n-r)
+    >end
+    >
+    >-- mfactorial doesn't seem noticeably faster
+    >function test_memo1()
+    >  for i=0,30 do
+    >    for j=0,i do
+    >      check_eq(num_permutations(i, j), mfactorial(i)/mfactorial(i-j), 'num_permutations memoizes: '..str(i)..'P'..str(j))
+    >    end
+    >  end
+    >end
+- __teliva_timestamp: original
   menu:
     >-- To show app-specific hotkeys in the menu bar, add hotkey/command
     >-- arrays of strings to the menu array.
d=e6cbe9c11e88537d74eb094ba5844f71ee57f268'>e6cbe9c ^
dc5c070 ^


e6cbe9c ^
e743836 ^
dc5c070 ^




901b3ed ^
1076f2b

901b3ed ^
0c3544d ^
72655f0 ^





901b3ed ^
72655f0 ^
3af6434 ^
72655f0 ^
3af6434 ^
72655f0 ^




3af6434 ^







72655f0 ^





3af6434 ^
72655f0 ^

7b5638f ^





1549faf ^


3af6434 ^

1549faf ^









ba59bc8 ^
1549faf ^
3af6434 ^

1549faf ^
0c3544d ^
0e5c819 ^












0c3544d ^

dc5c070 ^

5ef6ef1 ^

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112