Comment detail

ピラミッドを作る (Nested Flatten)
Emacs Lispです。Schemeのiota関数を使って、あとはmap*でイテレート。
mapは(require 'cl)すれば利用できたと思います。
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
(defun iota (count &optional from step)
  (let ((from (or from 0))
        (step (or step 1))
        (result nil))
    (while (> count 0)
      (setq result (cons from result)
            from (+ from step)
            count (- count 1)))
    (nreverse result)))

(defun pyramid (h)
  (mapc (lambda (s) (insert s ?\n))
        (mapcar (lambda (c)
                  (concat (make-string (car c) ?\ )
                          (make-string (cdr c) ?\*)))
                (map 'list 'cons (nreverse (iota h)) (iota h 1 2)))))

(pyramid 4)

Index

Feed

Other

Link

Pathtraq

loading...