Learning Programming Languages
Every year I try and learn a new language to help improve my thinking processes, identify what technologies are out there and as a means of practicing the fundamentals of programming from time to time. This article describes the various projects and thought processes that I go through in learning a new language.
Contents |
Thought Process
Languages are tools of the programming trade. There's little more to it. Granted, some are more appropriate for others given the right problem set, but largely there is no such thing as a perfect language.
Projects
Diving right in to a language through learning by doing.
Simple IO
Read in a file and print stats on lines, words, characters. Make it take parameters for the file location and optionally "switches" for which items should be counted.
Web Scraping/Spidering
Scrape a favourite website and build statistics, follow links.
Brute Force Perfect Shuffle
Implement a program that solves the following problem by brute force:
You are given a pack of cards containing X unique cards.
You are given a number Y that is less than X.
A shuffle is defined as the following:
Cut the pack Y cards from the top forming two portions: the top portion and the bottom portion
Put down the bottom card from the top portion and then the bottom card from the bottom portion
Continue in this manner alternating cards until one portion is used up
The remaining cards go on top
Write a function/method called noOfShuffles that taxes x and y and returns the number of shuffles
that are required in order to return the pack of cards to its original order. For any invalid
input values, -1 should be returned.
Generate Random Permutation
Based on the algorithm described in The Algorithm Design Manual on page 450, copied here for clarity:
for i = 1 to n do a[i] = i; for i = 1 to n-1 do swap[a[i], a[Random[i, n]];
IRC Client
Implement an IRC client, either an automated bot or a user client. Should be able to send and receive (parse and understand) incoming PRIVMSGs, and implement the most important protocol messages (e.g. CTCP VERSION).
The IRC RFCs can be found here: http://www.irchelp.org/irchelp/rfc/index.html
LIX Calculator
Create a LIX calculator for any specified text, reading from stdin and from flat-files.
LIX is a readability measure indicating the difficulty of reading a text developed by Swedish scholar Carl-Hugo Björnsson. It is computed as follows:
LIX = A/B + (C x 100)/A, where
A = Number of words
B = Number of periods (defined by period, colon or capital first letter)
C = Number of long words (More than 6 letters)