September 2017 Update
This commit is contained in:
parent
bba7bfd280
commit
ba8067c3b7
14570 changed files with 153136 additions and 63871 deletions
21
Task/Letter-frequency/Gambas/letter-frequency.gambas
Normal file
21
Task/Letter-frequency/Gambas/letter-frequency.gambas
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
Public Sub Form_Open()
|
||||
Dim sData As String = File.Load("data.txt")
|
||||
Dim iCount, iSpaces, iLetters, iOther As Integer
|
||||
Dim bPunctuation As Boolean
|
||||
|
||||
For iCount = 1 To Len(sData)
|
||||
If InStr("ABCDEFGHIJKLMNOPQRSTUVWXYZ", UCase(Mid(sData, iCount, 1))) Then
|
||||
Inc iLetters
|
||||
bPunctuation = True
|
||||
End If
|
||||
If Mid(sData, icount, 1) = " " Then
|
||||
Inc iSpaces
|
||||
bPunctuation = True
|
||||
End If
|
||||
If bPunctuation = False Then Inc iOther
|
||||
bPunctuation = False
|
||||
Next
|
||||
|
||||
Message("Text contains " & Len(sData) & " characters\n" & iLetters & " Letters\n" & iSpaces & " Spaces\n" & iOther & " Punctuation, newlines etc.")
|
||||
|
||||
End
|
||||
|
|
@ -1,3 +0,0 @@
|
|||
import Data.List
|
||||
|
||||
main = readFile "freq.hs" >>= mapM_ (\x -> print (head x, length x)) . group . sort
|
||||
|
|
@ -1,8 +0,0 @@
|
|||
import qualified Data.Map as M
|
||||
|
||||
main = do
|
||||
text <- readFile "freq.hs"
|
||||
let result = foldl (flip (M.adjust (+1))) initial text
|
||||
mapM_ print $ M.toList result
|
||||
|
||||
initial = M.fromList $ zipWith (\k v -> (toEnum k,v)) [0..255] (repeat 0)
|
||||
|
|
@ -1 +0,0 @@
|
|||
c@>c[;1]
|
||||
|
|
@ -1,10 +0,0 @@
|
|||
(("l";3)
|
||||
("o";2)
|
||||
("H";1)
|
||||
("e";1)
|
||||
(",";1)
|
||||
(" ";1)
|
||||
("w";1)
|
||||
("r";1)
|
||||
("d";1)
|
||||
("!";1))
|
||||
11
Task/Letter-frequency/Kotlin/letter-frequency.kotlin
Normal file
11
Task/Letter-frequency/Kotlin/letter-frequency.kotlin
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
// version 1.1.2
|
||||
|
||||
import java.io.File
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
val text = File("input.txt").readText().toLowerCase()
|
||||
val letterMap = text.filter { it in 'a'..'z' }.groupBy { it }.toSortedMap()
|
||||
for (letter in letterMap) println("${letter.key} = ${letter.value.size}")
|
||||
val sum = letterMap.values.sumBy { it.size }
|
||||
println("\nTotal letters = $sum")
|
||||
}
|
||||
|
|
@ -1,20 +1,36 @@
|
|||
-- Open the file named on the command line
|
||||
local file = assert(io.open(arg[1]))
|
||||
-- Keep a table counting the instances of each letter
|
||||
local instances = {}
|
||||
local function tally(char)
|
||||
-- normalize case
|
||||
char = string.upper(char)
|
||||
-- add to the count of the found character
|
||||
occurrences[char] = occurrences[char] + 1
|
||||
-- Return entire contents of named file
|
||||
function readFile (filename)
|
||||
local file = assert(io.open(filename, "r"))
|
||||
local contents = file:read("*all")
|
||||
file:close()
|
||||
return contents
|
||||
end
|
||||
-- For each line in the file
|
||||
for line in file:lines() do
|
||||
line:gsub(
|
||||
'%a', -- For each letter (%a) on the line,
|
||||
tally) --increase the count for that letter
|
||||
|
||||
-- Return a closure to keep track of letter counts
|
||||
function tally ()
|
||||
local t = {}
|
||||
|
||||
-- Add x to tally if supplied, return tally list otherwise
|
||||
local function count (x)
|
||||
if x then
|
||||
if t[x] then
|
||||
t[x] = t[x] + 1
|
||||
else
|
||||
t[x] = 1
|
||||
end
|
||||
else
|
||||
return t
|
||||
end
|
||||
end
|
||||
|
||||
return count
|
||||
end
|
||||
-- Print letter counts
|
||||
for letter, count in pairs(instances) do
|
||||
print(letter, count)
|
||||
|
||||
-- Main procedure
|
||||
local letterCount = tally()
|
||||
for letter in readFile(arg[1]):gmatch("%a") do
|
||||
letterCount(letter)
|
||||
end
|
||||
for k, v in pairs(letterCount()) do
|
||||
print(k, v)
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,2 +0,0 @@
|
|||
(my %count){$_}++ for lines.comb;
|
||||
.say for %count.sort;
|
||||
|
|
@ -1 +0,0 @@
|
|||
.say for bag(slurp.comb).pairs.sort;
|
||||
16
Task/Letter-frequency/Zkl/letter-frequency.zkl
Normal file
16
Task/Letter-frequency/Zkl/letter-frequency.zkl
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
fcn ccnt(textInBitBucket){
|
||||
letters:=["a".."z"].pump(List().write,0); // array of 26 zeros
|
||||
textInBitBucket.howza(0).pump(Void,'wrap(c){ // pump text as ints
|
||||
if(97<=c<=122) c-=97;
|
||||
else if(65<=c<=90) c-=65;
|
||||
else return(Void.Skip);
|
||||
letters[c]+=1
|
||||
});
|
||||
sum:=letters.sum(); println(sum," letters");
|
||||
letters.enumerate().pump(List,'wrap([(c,n)]){
|
||||
"%s(%d:%d%)".fmt((c+65).toChar(),n,n*100/sum)})
|
||||
.concat(",").println();
|
||||
}
|
||||
|
||||
ccnt(Data(0,Int,"This is a test"));
|
||||
ccnt(File("dict.txt").read());
|
||||
Loading…
Add table
Add a link
Reference in a new issue