Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
38
Task/Letter-frequency/Nanoquery/letter-frequency.nanoquery
Normal file
38
Task/Letter-frequency/Nanoquery/letter-frequency.nanoquery
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
// 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
|
||||
Loading…
Add table
Add a link
Reference in a new issue