about summary refs log tree commit diff stats
path: root/anagrams.tlv
diff options
context:
space:
mode:
Diffstat (limited to 'anagrams.tlv')
-rw-r--r--anagrams.tlv20
1 files changed, 18 insertions, 2 deletions
diff --git a/anagrams.tlv b/anagrams.tlv
index b48d5c4..d4ffc81 100644
--- a/anagrams.tlv
+++ b/anagrams.tlv
@@ -236,6 +236,7 @@
     >end
 - __teliva_timestamp: original
   count_letters:
+    >-- TODO: handle unicode
     >function count_letters(s)
     >  local result = {}
     >  for i=1,s:len() do
@@ -249,6 +250,21 @@
     >  return result
     >end
 - __teliva_timestamp: original
+  count:
+    >-- turn an array of elements into a map from elements to their frequency
+    >-- analogous to count_letters for non-strings
+    >function count(a)
+    >  local result = {}
+    >  for i, v in ipairs(a) do
+    >    if result[v] == nil then
+    >      result[v] = 1
+    >    else
+    >      result[v] = result[v] + 1
+    >    end
+    >  end
+    >  return result
+    >end
+- __teliva_timestamp: original
   union:
     >function union(a, b)
     >  for k, v in pairs(b) do
@@ -488,8 +504,8 @@
     >function count_anagrams(s)
     >  local result = factorial(s:len())
     >  local letter_counts = count_letters(s)
-    >  for k, v in pairs(letter_counts) do
-    >    result = result / factorial(v)
+    >  for l, cnt in pairs(letter_counts) do
+    >    result = result / factorial(cnt)
     >  end
     >  return result
     >end
<unknown> 2006-12-07 14:39:31 +0100 committer arg@mig29 <unknown> 2006-12-07 14:39:31 +0100 found compromise for fonts' href='/acidbong/suckless/dwm/commit/config.default.h?h=4.3&id=a3319c6f8e82522ce118b9a62124548d6f9cba09'>a3319c6 ^
b55bd70 ^

97ced11 ^

b55bd70 ^


19390b1 ^
97ced11 ^
0b80d18 ^
19390b1 ^
b515765 ^

b515765 ^
19dcbc5 ^






8c4623d ^

42fd392 ^
19dcbc5 ^












42fd392 ^
19dcbc5 ^










b515765 ^

d6a6eca ^
2dd5212 ^
b515765 ^

d6a6eca ^
e21d93b ^
a08d83b ^
b515765 ^
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