diff options
author | siddharth <s@ricketyspace.net> | 2021-06-19 11:47:30 -0400 |
---|---|---|
committer | siddharth <s@ricketyspace.net> | 2021-06-19 11:47:30 -0400 |
commit | d90053b1bb6620dc999f723d64aadccfbe6e0bbf (patch) | |
tree | 9d4d593727052cd471de513e2552ce251986e11e /lib | |
parent | e285c8aa4a03b4f96b1ab36a0fd4b1a6e810ec4b (diff) |
lib: add PrintableAscii, AsciiScores
Extracted from challenge 19
Diffstat (limited to 'lib')
-rw-r--r-- | lib/str.go | 27 |
1 files changed, 27 insertions, 0 deletions
@@ -3,6 +3,33 @@ package lib +// Key: ASCII character; Value: score +var AsciiScores map[byte]int = make(map[byte]int, 0) + +// Printable ASCII characters orrdered by frequency. +// (https://mdickens.me/typing/letter_frequency.html) +var PrintableAscii []byte = []byte{ + ' ', 'e', 't', 'a', 'o', 'i', 'n', 's', 'r', 'h', 'l', 'd', + 'c', 'u', 'm', 'f', 'g', 'p', 'y', 'w', 'b', ',', '.', + 'v', 'k', '-', '"', '_', '\'', 'x', ')', '(', ';', '0', 'j', + '1', 'q', '=', '2', ':', 'z', '/', '*', '!', '?', '$', '3', + '5', '>', '{', '}', '4', '9', '[', ']', '8', '6', '7', '\\', + '+', '|', '&', '<', '%', '@', '#', '^', '`', '~', +} + +func init() { + // Initialize AsciiScores + for pos, a := range PrintableAscii { + AsciiScores[a] = 255 - pos + // Also add the uppercase version of ascii + // character if it exists. + au := ByteToUpper(a) + if a != au { + AsciiScores[au] = 255 - pos + } + } +} + func FillStr(a string, l int) string { b := "" if l < 1 { |