2016 Update

This commit is contained in:
Tina Müller 2016-12-05 22:15:40 +01:00
parent 948b86eafa
commit dcf5d15da3
7965 changed files with 139854 additions and 31002 deletions

View file

@ -1,4 +1,6 @@
;Task:
Open a text file and count the occurrences of each letter.
Some of these programs count all characters (including punctuation),
but some only count letters A to Z.
<br><br>

View file

@ -1,11 +1,9 @@
file = hd(System.argv)
case File.read(file) do
{:ok, binary} -> String.upcase(binary)
|> String.codepoints
|> Enum.filter(fn c -> c =~ ~r/[A-Z]/ end)
|> Enum.reduce(Map.new, fn c,acc -> Dict.update(acc, c, 1, &(&1+1)) end)
|> Enum.sort_by(fn {_k,v} -> -v end)
|> Enum.each(fn {k,v} -> IO.puts "#{k} #{v}" end)
{:error, reason} -> IO.inspect reason
end
File.read!(file)
|> String.upcase
|> String.graphemes
|> Enum.filter(fn c -> c =~ ~r/[A-Z]/ end)
|> Enum.reduce(Map.new, fn c,acc -> Map.update(acc, c, 1, &(&1+1)) end)
|> Enum.sort_by(fn {_k,v} -> -v end)
|> Enum.each(fn {k,v} -> IO.puts "#{k} #{v}" end)

View file

@ -1,5 +1,5 @@
function freq(file)
h = Dict{Char, Integer}()
for x in open(readchomp,file) h[x] = get(h,x,0)+1 end
for x in open(readstring ,file) h[x] = get(h,x,0)+1 end
sort(collect(h))
end

View file

@ -0,0 +1,10 @@
open Batteries
let frequency file =
let freq = Hashtbl.create 52 in
File.with_file_in file
(Enum.iter (fun c -> Hashtbl.modify_def 1 c succ freq) % Text.chars_of);
List.iter (fun (k,v) -> Text.write_text stdout k;
Printf.printf " %d\n" v)
@@ List.sort (fun (_,v) (_,v') -> compare v v')
@@ Hashtbl.fold (fun k v l -> (Text.of_uchar k,v) :: l) freq []

View file

@ -0,0 +1,9 @@
function frequency ($string) {
$arr = $string.ToUpper().ToCharArray() |where{$_ -match '[A-KL-Z]'}
$n = $arr.count
$arr | group | foreach{
[pscustomobject]@{letter = "$($_.name)"; frequency = "$([math]::round($($_.Count/$n),5))"; count = "$($_.count)"}
} | sort letter
}
$file = "$($MyInvocation.MyCommand.Name )" #Put the name of your file here
frequency $(get-content $file -Raw)