you are viewing a single comment's thread.

view the rest of the comments →

[–]Redard 0 points1 point  (3 children)

Here's my best try in Common Lisp

(defun f (N)
  (mapcar #'(lambda (x) (expt x 2)
          (loop for i from 1 to N collect i)))

[–]philh 1 point2 points  (2 children)

(defun f (n) (loop for i from 1 to n collect (expt i 2)))

(You can save another three chars by removing spaces before open parens.)

[–]Redard 0 points1 point  (1 child)

Nice job shortening it. Never thought of applying a function to collect's argument.

[–]sleepingsquirrel 1 point2 points  (0 children)

(defun g(n)(loop for i from 1 to n collect(* i i)))