Concept:
Greatest common divisor
Headline
The greatest common divisor of two integers
Illustration
We face an algorithmic problem because the greatest common divisor can be computed by a (simple) algorithm.
- We assume (for simplicity) two positive operands x and y.
- Perform the following steps to return the greatest common divisor of x and y.
- Repeat the following step until x equals y:
- If x > y
- then subtract y from x and
- else subtract x from y.
- If x > y
- Return x.
- Repeat the following step until x equals y:
// Compute greatest common divisor
public static int gcd(int x, int y) {
// This version requires positive integers.
assert x > 0 && y > 0;
while (x != y) {
if (x > y)
x = x - y;
else
y = y - x;
}
return x;
}
Here is also an implementation in Language:Haskell:
-- Operands are supposed to be positive integers.
gcd :: Int -> Int -> Int
gcd x y | x > y = gcd (x-y) y
| x < y = gcd x (y-x)
| otherwise = x
Citation
(http://en.wikipedia.org/wiki/Greatest_common_divisor, 15 April 2013)
In mathematics, the greatest common divisor (gcd), also known as the greatest common factor (gcf), or highest common factor (hcf), of two or more integers (at least one of which is not zero), is the largest positive integer that divides the numbers without a remainder. For example, the GCD of 8 and 12 is 4.
Language:
Java
Headline
Illustration
Let's show "Hello World" for Java.
public class HelloWorld {
public static void main(String[] args) {
System.out.println("Hello, World");
}
}
Concept:
Algorithmic problem
Headline
A problem that can be solved with an algorithm
Illustration
- Examples of algorithmic problems: greatest common divisor, the factorial, and the search problem.
- An example of non-algorithmic problems: the Halting problem.
Language:
Haskell
Headline
The functional programming language Haskell
Details
101wiki hosts plenty of Haskell-based contributions. This is evident from corresponding back-links. More selective sets of Haskell-based contributions are organized in themes: Theme:Haskell data, Theme:Haskell potpourri, and Theme:Haskell genericity. Haskell is also the language of choice for a course supported by 101wiki: Course:Lambdas_in_Koblenz.
Illustration
The following expression takes the first 42 elements of the infinite list of natural numbers:
> take 42 [0..]
[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41]
In this example, we leverage Haskell's lazy evaluation.