Add functions to make a frequency map.
continuous-integration/drone/push Build is passing

This commit is contained in:
2023-10-24 21:24:03 +03:00
parent 6f70417b78
commit 172f85ea6f
2 changed files with 59 additions and 0 deletions
@@ -36,3 +36,22 @@
0
letter-counts)))
(defn sort-map-by-count
"Return a list of pairs from a map of pairs where a pair is a character and its count. The order is descending."
[count-map]
(->> count-map
(reduce (fn [acc [char count]] (conj acc [char count])) [])
(sort-by #(- (second %)))))
(defn table-to-string
"Return the string from a frequency table."
[table]
(->> (map first table)
(apply str)))
(defn symbol-frequency-table
"Return a table where pairs is a symbol from a cipher text and its value which is a symbol from frequency table."
[cipher-table frequency-table]
(zipmap (table-to-string (sort-map-by-count cipher-table))
(table-to-string (sort-map-by-count frequency-table))))