Letter frequency: Difference between revisions

Content added Content deleted
(Added zkl)
Line 2,769: Line 2,769:
Example output of count.xpl counting itself:
Example output of count.xpl counting itself:
[[File:Count2XPL0.gif]]
[[File:Count2XPL0.gif]]

=={{header|zkl}}==
<lang zkl>
fcn ccnt(textInBitBucket){
letters:=[1..26].pump(0,List,(0).create.fp(0)).copy();
textInBitBucket.pump('wrap(c){
if(97<=c<=122) c-=97;
else if(65<=c<=90) c-=65;
else return(Void.Skip);
letters[c]=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());</lang>
{{out}}
<pre>
11 letters
A(1:9%),B(0:0%),C(0:0%),D(0:0%),E(1:9%),F(0:0%),G(0:0%),H(1:9%),I(2:18%),J(0:0%),K(0:0%),L(0:0%),M(0:0%),N(0:0%),O(0:0%),P(0:0%),Q(0:0%),R(0:0%),S(3:27%),T(3:27%),U(0:0%),V(0:0%),W(0:0%),X(0:0%),Y(0:0%),Z(0:0%)

181171 letters
A(16421:9%),B(4115:2%),C(8216:4%),D(5799:3%),E(20144:11%),F(2662:1%),G(4129:2%),H(5208:2%),I(13980:7%),J(430:0%),K(1925:1%),L(10061:5%),M(5828:3%),N(12097:6%),O(12738:7%),P(5516:3%),Q(378:0%),R(13436:7%),S(10210:5%),T(12836:7%),U(6489:3%),V(1902:1%),W(1968:1%),X(617:0%),Y(3633:2%),Z(433:0%)
</pre>