ComputeFrequenciesString := proc(s::string) local T,i,c,l; T := table(); l := length(s); for i from 1 to l do c := s[i]; if whattype(T[c])<>integer then T[c] := 1; else T[c] := T[c] + 1; end if; end do; i := indices(T); for c in i do T[op(c)] := 100*evalf(T[op(c)]/l); end do; T end proc; ComputeFrequenciesNum := proc(a::integer) local T,i,c,l; T := table(); i := a; l := 0; ### l = the number of two-digit blocks processed while i>0 do c := i mod 100; if whattype(T[c])<>integer then T[c] := 1; else T[c] := T[c] + 1; end if; i := (i - c)/100; l := l + 1; end do; i := indices(T); for c in i do T[op(c)] := 100*evalf(T[op(c)]/l); end do; T end proc; PrintFrequencies := proc(F::table) local clist; clist := sort([indices(F)], (a,b)->F[op(a)]>F[op(b)]); map(c->printf("f%s = %2.2f%%\n", convert(c,string), F[op(c)]), clist) end proc; FileToString := proc(filename::string) local s,line; s := ""; line := ""; while line <> 0 do s := cat(s,line,"\n"); line := readline(filename); end do; s end proc;