// SPDX-License-Identifier: WTFPL // cc -Wall -lm freq.c #include #include #include #include struct table { char ch; double freq; }; const struct table entry[] = { {'z', 0.00074}, {'q', 0.00095}, {'x', 0.00150}, {'j', 0.00153}, {'k', 0.00772}, {'v', 0.00978}, {'b', 0.01492}, {'p', 0.01929}, {'y', 0.01974}, {'g', 0.02015}, {'f', 0.02228}, {'w', 0.02360}, {'m', 0.02406}, {'u', 0.02758}, {'c', 0.02782}, {'l', 0.04025}, {'d', 0.04253}, {'r', 0.05987}, {'h', 0.06094}, {'s', 0.06327}, {'n', 0.06749}, {'i', 0.06966}, {'o', 0.07507}, {'a', 0.08167}, {'t', 0.09056}, {'e', 0.12702}, }; static void display_result_log(char ch, double ratio, double base) { int i, n; ratio *= base; n = log(ratio) / log(base) + 0.5; for (i = 0; i < n; i++) putchar(ch); } static void display_result_linear(char ch, double ratio, double base) { int i, n; n = ratio * 2 + 0.5; for (i = 0; i < n; i++) putchar(ch); } int main(int argc, char *argv[]) { int i; double d, base; void (*func)(char, double, double); base = (argc < 2) ? exp(1) : atof(argv[1]); func = (base < 1.0) ? display_result_linear : display_result_log; printf("CharGroup0 = "); for (i = sizeof(entry) / sizeof(struct table) - 1; i >= 0; i--) { d = entry[i].freq / entry[0].freq; (*func)(entry[i].ch, d, base); } printf("\n"); return 0; }