diff options
-rw-r--r-- | anagrams.tlv | 20 | ||||
-rw-r--r-- | break.tlv | 16 | ||||
-rw-r--r-- | gemini.tlv | 16 | ||||
-rw-r--r-- | graphviz.tlv | 16 | ||||
-rw-r--r-- | life.tlv | 16 | ||||
-rw-r--r-- | template.tlv | 16 | ||||
-rw-r--r-- | toot-toot.tlv | 16 | ||||
-rw-r--r-- | zet.tlv | 16 |
8 files changed, 130 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 diff --git a/break.tlv b/break.tlv index 34cbe78..36041e6 100644 --- a/break.tlv +++ b/break.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 diff --git a/gemini.tlv b/gemini.tlv index 96a7b03..f661a21 100644 --- a/gemini.tlv +++ b/gemini.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 diff --git a/graphviz.tlv b/graphviz.tlv index 0bdd67b..18fb7e0 100644 --- a/graphviz.tlv +++ b/graphviz.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 diff --git a/life.tlv b/life.tlv index e35fd59..eba123f 100644 --- a/life.tlv +++ b/life.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 diff --git a/template.tlv b/template.tlv index 586b640..829c4ab 100644 --- a/template.tlv +++ b/template.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 diff --git a/toot-toot.tlv b/toot-toot.tlv index b03d209..375d503 100644 --- a/toot-toot.tlv +++ b/toot-toot.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 diff --git a/zet.tlv b/zet.tlv index b3d1c90..fcc66a8 100644 --- a/zet.tlv +++ b/zet.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 |