Zbr's days.
May
Sun Mon Tue Wed Thu Fri Sat
       
25
2008
Months
May
Oct Nov Dec

About TODO Blog RSS Old blog Projects Gallery Notes

Sun, 25 May 2008

Every lisper did that.

#!/usr/bin/clisp
(defun f (m)
  (do ((k 0 (1+ k))
       (c 0 n)
       (n 1 (+ c n)))
    ((eql k m)
     (format t "~r" c))))
(f 317)

Guess the result:seven hundred and ninety-three vigintillion, five hundred and ninety-one novemdecillion, four hundred and seven octodecillion, eight hundred and four septendecillion, one hundred and fifty-one sexdecillion, nine hundred and twenty-six quindecillion, five hundred and ninety-three quattuordecillion, seven hundred and ninety-three tredecillion, forty-two duodecillion, one hundred and twenty-six undecillion, eight hundred and ninety-one decillion, one hundred and twenty-eight nonillion, eight hundred and nineteen octillion, six hundred and ten septillion, seven hundred and ten sextillion, one hundred and forty quintillion, one hundred and forty-five quadrillion, thirty-seven trillion, nine hundred and fifty-eight billion, two hundred and seventy-three million, seven hundred and seventy-seven thousand, three hundred and ninety-seven

/devel/other :: Link / Comments (4)

nikita wrote at 2008-05-26 00:22:

What is the last N for which it can calculate (ack N N), where

(defun ack (m n) (cond ((eql m 0) (+ n 1)) ((eql n 0) (ack (- m 1) 1)) (t (ack (- m 1) (ack m (- n 1))))))

?

Zbr wrote at 2008-05-26 00:51:

I frankly tried 10 and 1 in mind, the former would loop forver as I understood, the latter does not. Likely the answer is somewhere in between, practice showed that 3 works and 4 loops forever (until there is a memory for recursion I think).

Actually I wanted to show all those literal names for huge numbers as "~r" format provides :), pieces of my math knowledge only contains duodecillion. And number of parentesis of course, but I'm starting to like them when write in vim and not clisp command line.

nikita wrote at 2008-05-26 01:04:

Not forever, of course. It is just that this function (http://en.wikipedia.org/wiki/Ackermann_function) grows very very fast.

Zbr wrote at 2008-05-26 01:23:

Yep, 'forever' in terms that I cancelled both mind and computer execution :) When I tried 10 in mind I stopped somewhat in the middle of the second 'big' recursion invocation (i.e. which drops to the latest condition being evaluated), I did not calculate values, but instead stepped instructions one after another with loops, that was already not cool, since I thought originally that there is a limit below which function will collapse and it is that limit you asked for. Wikipedia shows that there is no such a limit at all and function just grows rapidly.

Thanks for the link, I will read it for interest.

Please solve this captcha to be allowed to post (need to reload in a minute): 1 * 18

Comments are closed for this story.