[ prog / sol / mona ]

prog


LISP Puzzles

1 2020-04-03 16:19

I've found a fun little paper while doing the ACM game in /prog/98. It's just four easy LISP puzzles. I'll copy them below for your amusement. Replace "DE" with "defun" obviously.

(Hofstadter) Write a LISP function to generate the following set of integers (1 3 7 12 18 26 35 45 56 ...

(Hofstadter) This is the function g. What is she doing?

(DE g (n)
  (IF (ZEROP n) 0
      (- n (g (g (SUB1 n))))))

"and what about the function q?"

(DE q (n)
  (COND ((= n 1) 1)
        ((= n 2) 1)
        (T (+ (q (- n (q (SUB1 n))))
              (q (- n (q (- n 2))))))))

(Bratley, Milo) This is the function FOO. What is she doing?

(DE foo NIL
  (PRINT (APPEND (QUOTE (DE foo))
                 (CDR (GET (QUOTE foo)
                           (QUOTE EXPR)))))
  (PRINT (QUOTE (foo))))
(foo)

(Goossens) This is the function BAR. What is she doing?

(DE bar (l x)
  (IF (NULL l) x
      (bar (REVERSE (CDR L)) (CAR L))))

link: https://dl.acm.org/doi/10.1145/1411829.1411830
I never knew functions were female also 100 GET

157


VIP:

do not edit these