mnemonics.frink

View or download mnemonics.frink in plain text format


// Program to create mnemonic words for numbers.

// Giordano system mapping, which is bad.
//            0    1     2       3      4       5       6       7       8     9
// Giordano system
//letterMap = ["M", "N", "T H Z", "B", "W V K", "F R", "J P X", "S D", "G Q L", "C"]

// Alan's quick-and-dirty system:
// letterMap = ["N", "T", "H", "S", "R", "D V", "C Y K", "L P", "M G B", "F W X J Q Z"]

// Steve Clymer's system:
letterMap = ["R", "T", "N", "L", "S Z", "H Y", "D G J", "P B F", "M W V", "C K Q X"]

letterToNumberMap = invertMap[letterMap]

words = new dict
words@10000=1

println["<TABLE BORDER=0>"]

// Read in nouns and verbs from the "parts of speech" data file.
// The wordlist files are part of the Moby wordlist project, available at:
//   http://icon.shef.ac.uk/Moby/
for line = lines["file:///home/eliasen/prog/mobydict/mpos/partsofspeech.txt", "ISO8859_1"]
   if [word] = line =~ %r/^([a-z\-\s]*)\xD7.*[NVitph]/
   {
      num = ""
      // Turn word into just its consonants.
      for letter = chars[uc[word]]
      {
         c = char[letter]
         if letterToNumberMap@c != undef
            num = num + letterToNumberMap@c
      }
      if length[num] >= 3 and length[num] <= 4
      {
         println["<TR><TD>$word<TD>$num"]
         if words@num
            words@num.push[word]
         else
            words@num=[word]
      }
   }

println["</TABLE>"]

count3 = 0
   
println["<TABLE BORDER=0>"]
for i = 0 to 999
{
   pad = right["00" + i, 3]     // Pad the number with zeroes.
   if words.containsKey[pad]
   {
      println["<TR><TD>$pad<TD>" + join[", ", words@pad]]
      count3 = count3 + 1
   } else
      println["<TR><TD>$pad<TD>"]
}

count4 = 0
for i = 0 to 9999
{
   pad = right["000" + i, 4]     // Pad the number with zeroes.
   if words.containsKey[pad]
   {
      println["<TR><TD>$pad<TD>" + join[", ", words@pad]]
      count4 = count4 + 1
   } else
      println["<TR><TD>$pad<TD>"]
}

println["</TABLE>"]

println["3-Letter words covered: " + count3 + "\t(" + format[count3/1000, percent, 3] + "%)<BR>"]
println["4-Letter words covered: " + count4 + "\t(" + format[count4/10000, percent, 3] + "%)<BR>"]
println["Total words covered: " + (count3+count4) + "\t(" + format[(count3+count4)/11000, percent, 3] + "%)<BR>"]

// Turns an array with each element separated by spaces into a dictionary
// where the key is the symbol and the value is the number.
invertMap[orig] :=
{
   result = new dict

   idx = 0
   for codes = orig
   {
      for token = split[%r/\s+/g, codes]
         result@token = idx

      idx = idx + 1
   }
   return result
}


View or download mnemonics.frink in plain text format


This is a program written in the programming language Frink.
For more information, view the Frink Documentation or see More Sample Frink Programs.

Alan Eliasen was born 17592 days, 15 hours, 39 minutes ago.