Letter frequency: Difference between revisions

Added Wren
(→‎{{header|R}}: Table solution)
(Added Wren)
Line 5,622:
55
119</pre>
 
=={{header|Wren}}==
{{libheader|Fmt}}
As we have a copy to hand, we count the number of letters in the MIT 10000 word list which apparently contains nothing other than lower case letters.
<lang ecmascript>import "io" for File
import "/fmt" for Fmt
 
var text = File.read("mit10000.txt")
var freqs = List.filled(26, 0)
for (c in text.codePoints) {
if (c >= 97 && c <= 122) {
freqs[c-97] = freqs[c-97] + 1
}
}
var totalFreq = freqs.reduce { |sum, f| sum + f }
System.print("Frequencies of letters in mit10000.txt:")
System.print("\n freq \%")
System.print("----------------")
 
for (i in 0..25) {
Fmt.print("$c $5d $6.2f", i+97, freqs[i], freqs[i]/totalFreq * 100)
}
System.print(" ----- ------")
Fmt.print(" $5d 100.00", totalFreq)
 
Fmt.print("\nTotal characters in text file = $d minus 10000 \\n's = $d", text.count, totalFreq)</lang>
 
{{out}}
<pre>
Frequencies of letters in mit10000.txt:
 
freq %
----------------
a 5378 8.16
b 1141 1.73
c 3025 4.59
d 2507 3.81
e 7601 11.54
f 927 1.41
g 1717 2.61
h 1429 2.17
i 5461 8.29
j 183 0.28
k 592 0.90
l 3231 4.90
m 1912 2.90
n 4822 7.32
o 4252 6.45
p 2027 3.08
q 123 0.19
r 4860 7.38
s 5085 7.72
t 4760 7.23
u 1939 2.94
v 849 1.29
w 632 0.96
x 264 0.40
y 1027 1.56
z 136 0.21
----- ------
65880 100.00
 
Total characters in text file = 75880 minus 10000 \n's = 65880
</pre>
 
 
=={{header|XPL0}}==
9,490

edits