User:Arcorann/TPK Algorithm
Jump to navigation
Jump to search
The TPK algorithm is an algorithm used by Luis Trabb Pardo and Donald Knuth in the 1977 paper "The Early Development of Programming Languages" to demonstrate various features of early (pre-1960) programming languages.
Algorithm
The algorithm was described in Algol 60 as follows:
begin integer i; real y; real array a[0:10]; real procedure f(t); real t; value t; f := sqrt(abs(t)) + 5 * t ^ 3; for i := 0 step 1 until 10 do read(a[i]); for i := 10 step -1 until 0 do begin y := f(a[i]); if y > 400 then write(i, "TOO LARGE") else write(i, y); end end
The authors specified the following alterations for languages which did not support all the operations used in the algorithm:
- If the language does not support non-integer numbers, then the square root function should round down to the nearest integer.
- If the language does not support text output, the alert function should instead print 999.
- If the language does not support output of any kind, the algorithm should store an array of 22 values alternating between the index of the input (zero-indexed i.e. 10, 9, ... , 0) followed by the corresponding output value.