Pure Programmer
Blue Matrix


Cluster Map

Project: Frequency Table (Characters)

Write a program to generate a table of frequencies. The program should accept a stream on stdin and total the number of each character seen. Once the stream has been read the program should print a tab-delimited table with columns for Codepoint in hexadecimal, Character, Count, and Frequency. The frequency of each character is the count for that character divided by the total number of characters in the file.

You can capture webpages using the 'curl' program as tests for your program. If the webpage is encoded in ISO-8859-1 (Latin-1) instead of Unicode you can convert it using the 'iconv' program. For example:

$ curl https://pt.lipsum.com/ | iconv -f ISO-8859-1 -t UTF-8 | ./FrequencyTableChars $ curl https://cn.lipsum.com/ | ./FrequencyTableChars

Output
$ swiftc FrequencyTableChars.swift -I . -L . -lUtils error: link command failed with exit code 1 (use -v to see invocation) ld: library not found for -lUtils clang: error: linker command failed with exit code 1 (use -v to see invocation) $ swiftc FrequencyTableChars.swift -I . -L . -lUtils error: link command failed with exit code 1 (use -v to see invocation) ld: library not found for -lUtils clang: error: linker command failed with exit code 1 (use -v to see invocation)

Solution