Array: Difference between revisions

Content added Content deleted
m (Grammar)
Line 67: Line 67:
sums (letters I. (~. reduced))} 26 # 0 NB. Alphabetize the sums, then return.
sums (letters I. (~. reduced))} 26 # 0 NB. Alphabetize the sums, then return.
)
)

==[[OCaml]]==
same task, open a text file and compute letter frequency

<ocaml>let () =
let ic = open_in Sys.argv.(1) in
let base = int_of_char 'a' in
let arr = Array.make 26 0 in
try while true do
let c = Char.lowercase(input_char ic) in
let ndx = int_of_char c - base in
if ndx < 26 && ndx >= 0 then
arr.(ndx) <- succ arr.(ndx)
done
with End_of_file ->
close_in ic;
for i=0 to 25 do
Printf.printf "%c -> %d\n" (char_of_int(i + base)) arr.(i)
done</ocaml>


==Computational metrics==
==Computational metrics==