2008-03-01から1ヶ月間の記事一覧

P10: 連続して出現する要素をまとめ、それぞれ出現回数を求める。

P09の成果を使う。 ;;; ;; P10 (*) Run-length encoding of a list. ;; Use the result of problem P09 to implement the so-called run-length ;; encoding data compression method. Consecutive duplicates of elements ;; are encoded as lists (N E) wh…

日記始めました

ブログがあるといろいろ便利そうなので、遅ればせながらブログ始めました。

P05: list反転

まだ、dolistでいける。 ;;; ;;; P05 (*) Reverse a list. ;;; Example: ;;; * (my-reverse '(a b c)) ;;; (c b a) (defun my-reverse (list) (let ((result nil)) (dolist (element list) (push element result)) result))

P04: lengthを実装

PAIP本から借用。dolistで実装。 ;;; ;;; P04 (*) Find the number of elements of a list. ;;; (defun my-length (list) (let ((i 0)) (dolist (l list) (incf i)) i))

P03: index番目の要素を返す。ただし1基底

まだ、doで何とかなる。 ;;; ;;; P03 (*) Find the K'th element of a list. ;;; The first element in the list is number 1. ;;; Example: ;;; * (element-at '(a b c d e) 3) ;;; C (defun element-at (list index) (do ((l list (cdr l)) (i 1 (1+ i))) …

P02: 最後の一つ手前のcons cellを見つける

doで実装。一つ手前のcons cellをresultへ保持。 ;;; ;;; P02 (*) Find the last but one box of a list. ;;; Example: ;;; * (my-but-last '(a b c d)) ;;; (C D) (defun my-but-last (list) (let ((result nil)) (do ((l list (cdr l))) ((not (consp (cdr…

P01: 最後のcons cellを見つける

PAIP読書会で知り合ったid:g000001さんから、L-99を勧められたので挑戦してみる。 取りあえず1問目から。doで実装してみる。 ;;; ;;; P01 (*) Find the last box of a list. ;;; Example: ;;; * (my-last '(a b c d)) ;;; (D) (defun my-last (list) (do ((l…