kacchi #319(2007/07/07 15:26 GMT) [ Emacs Lisp ] Rating0/0=0.00
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)
Rating0/0=0.00-0+
[ reply ]
kacchi
#319()
[
Emacs Lisp
]
Rating0/0=0.00
(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)Rating0/0=0.00-0+
[ reply ]