Code
Here is an implementation of the recursive algorithm in Lisp:
(defun mc91 (n) (cond ((<= n 100) (mc91 (mc91 (+ n 11)))) (t (- n 10))))Here is an implementation of the recursive algorithm in C:
int mc91(int n) { if (n > 100) { return n - 10; } else { return mc91(mc91(n+11)); } }Here is an implementation of the non-recursive algorithm in C:
int mccarthy(int n) { int c; for (c = 1; c != 0; ) { if (n > 100) { n = n - 10; c--; } else { n = n + 11; c++; } } return n; }Read more about this topic: McCarthy 91 Function
Famous quotes containing the word code:
“Faultless honesty is a sine qua non of business life. Not alone the honesty according to the moral code and the Bible. When I speak of honesty I refer to the small, hidden, evasive meannesses of our natures. I speak of the honesty of ourselves to ourselves.”
—Alice Foote MacDougall (18671945)
“Wise Draco comes, deep in the midnight roll
Of black artillery; he comes, though late;
In code corroborating Calvins creed
And cynic tyrannies of honest kings;
He comes, nor parlies; and the Town, redeemed,
Gives thanks devout; nor, being thankful, heeds
The grimy slur on the Republics faith implied,
Which holds that Man is naturally good,
Andmoreis Natures Roman, never to be
scourged.”
—Herman Melville (18191891)
“Hollywood keeps before its child audiences a string of glorified young heroes, everyone of whom is an unhesitating and violent Anarchist. His one answer to everything that annoys him or disparages his country or his parents or his young lady or his personal code of manly conduct is to give the offender a sock in the jaw.... My observation leads me to believe that it is not the virtuous people who are good at socking jaws.”
—George Bernard Shaw (18561950)