The Luhn test is used by some credit card companies to distinguish valid credit card numbers from what could be a random selection of digits. Those
Continue ReadingC++: Dining Philosophers
The dining philosophers problem illustrates non-composability of low-level synchronization primitives like semaphores. It is a modification of a probl
Continue ReadingC++: Input/Output for Pairs of Numbers
From lines of input starting with a line containing the numbers of pairs to follows, followed by that number of pairs of integers separated by a space
Continue ReadingC++: LZW Compression
The Lempel-Ziv-Welch (LZW) algorithm provides lossless data compression. You can read a complete description of it in the Wikipedia article on the sub
Continue ReadingC++: Floyd’s Triangle
Floyd's triangle lists the natural numbers in a right triangle aligned to the left where the first row is just 1 successive rows start towards
Continue ReadingC++: Balanced Brackets
Task: Generate a string with N opening brackets (“[”) and N closing brackets (“]”), in some arbitrary order. Determine whether the gen
Continue ReadingC++: Generate Chess960 Starting Position
Chess960 is a variant of chess created by world champion Bobby Fisher. Unlike other variants of the game, Chess960 does not require a different materi
Continue ReadingC++: Knuth’s Algorithm S
This is a method of randomly sampling n items from a set of M items, with equal probability; where M >= n and M, the number of items is unknown unt
Continue ReadingC++: Knapsack Problem
A tourist wants to make a good trip at the weekend with his friends. They will go to the mountains to see the wonders of nature, so he needs to pack w
Continue ReadingC++: Box the Compass
Avast me hearties! There be many a land lubber that knows naught of the pirate ways and gives direction by degree! They know not how to box the com
Continue Reading