This commit is contained in:
@@ -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))))
|
||||
|
||||
|
||||
Reference in New Issue
Block a user