Letter frequency: Difference between revisions

Content added Content deleted
(Added solution for Action!)
No edit summary
Line 3,559: Line 3,559:


Total letters = 64
Total letters = 64
</pre>

=={{header|Ksh}}==
<lang ksh>
#!/bin/ksh

# Count the occurrences of each character

######
# main #
######

typeset -iA freqCnt
while read; do
for ((i=0; i<${#REPLY}; i++)); do
(( freqCnt[${REPLY:i:1}]++ ))
done
done < $0 ## Count chars of this code file

for ch in "${!freqCnt[@]}"; do
[[ ${ch} == ?(\S) ]] && print -- "${ch} ${freqCnt[${ch}]}"
done
</lang>
{{out}}
Counts the characters of the source code file
<pre>
! 2
" 4
# 19
$ 8
& 2
( 5
) 5
+ 4
- 3
/ 2
0 2
1 1
: 2
; 5
< 2
= 3
? 1
@ 1
A 1
C 6
E 2
L 2
P 2
R 2
S 1
Y 2
[ 5
] 5
a 6
b 1
c 12
d 8
e 18
f 9
h 11
i 12
k 1
l 2
m 1
n 14
o 14
p 2
q 4
r 13
s 5
t 12
u 3
w 1
y 1
{ 7
</pre>
</pre>