39 lines
1.0 KiB
Plaintext
39 lines
1.0 KiB
Plaintext
// define a list to hold characters and amounts
|
|
characters = list()
|
|
amounts = list()
|
|
|
|
// define the alphabet as a string to check only letters and numbers
|
|
alpha = "abcdefghijklmnopqrstuvwxyz0123456789"
|
|
|
|
// get the filename as an argument
|
|
fname = args[len(args) - 1]
|
|
|
|
// read the entire file into a string
|
|
contents = new(Nanoquery.IO.File, fname).readAll()
|
|
|
|
// loop through all the characters in the array
|
|
for i in range(0, len(contents) - 1)
|
|
// get the character to check
|
|
toCheck = str(contents[i]).toLowerCase()
|
|
|
|
// check if the current character is in the array
|
|
if ((alpha .contains. toCheck) && (characters .contains. toCheck))
|
|
// if it's there, increment its amount
|
|
index = characters[toCheck]
|
|
amounts[index] = amounts[index] + 1
|
|
else
|
|
if (alpha .contains. toCheck)
|
|
// if it's not, add it
|
|
append characters toCheck
|
|
append amounts 0
|
|
end
|
|
end if
|
|
end for
|
|
|
|
// output the amounts
|
|
println format("%-20s %s", "Character", "Amount")
|
|
println "=" * 30
|
|
for i in range(0, len(characters) - 1)
|
|
println format("%-20s %d", characters[i], amounts[i])
|
|
end for
|