I don't want to use an extension or dictionary, which I know means creating a list (or lists) that has 26 items to keep track of counts. I also know that I need to use the text split/at block and loop through the string. Has anybody already created something like this that I can use as a model? It would be greatly appreciated.
(Before you ask, no it is not a homework assignment. I'm actually a math teacher trying to limp through teaching an Intro to Comp Sci class, our current unit is Cryptography and this app would work well with the Frequency Analysis lesson.)
I want to stick to lists because it's an Intro class and that's a concept the students are familiar with. Considering this is a tool to use within the lesson I don't want to struggle with more complex structures if they can be avoided.
Without extension, dictionary, anyother global list
When Button1.Click:
set inputText to TextBox1.Text
initialize empty list uniqueChars
initialize empty list counts
for each character in (split inputText into characters):
if character not in uniqueChars:
add character to uniqueChars
add 1 to counts
else:
index = index of character in uniqueChars
counts[index] = counts[index] + 1
initialize empty list result
for each index in uniqueChars:
create string "character - count"
add to result
set ListView1.Elements to result
above blocks are draggable (pls add caps in the code there by all letters into cap)
Split the letters
Sort the letters
Walk the list from the end to the front, at each step gobbling up the predecessor if it matches.
(Going in descending index order is necessary because the indexes collapse at each removal.)
This leaves you with a list of letter sequences (aaa,b,nn) one per letter, each holding all the instances of that letter.
The graph and the summary are fed from the letter and the matching sequence length.