トランプを配る

http://ameblo.jp/programming/entry-10001721422.html
制限時間10分って言ってるのに1時間以上かかった、もうだめぽ

(defun replace-nth (SEQ INDEX NEW &optional RET)
  (when (and RET (> INDEX (length SEQ)))
    (error "replace-nth: INDEX is higher than length of SEQ; SEQ: ~S; INDEX ~S"
           SEQ INDEX))
  (if (zerop INDEX)
      (append (reverse RET) (list NEW) (cdr SEQ))
    (replace-nth (cdr SEQ) (1- INDEX) NEW (cons (car SEQ) RET))))

(defun deal (n-players deck &optional (cards (make-list n-players :initial-element "")) (c 0))
  ;(msgbox "N: ~S~%deck: ~S~%cards: ~S~%c: ~S" n-players deck cards c)
  (if (or (equal deck "")
          (and (zerop c) (> n-players (length deck))))
      cards
    (deal n-players
          (subseq deck 1)
          (replace-nth cards c (concat (nth c cards) (string (elt deck 0))))
          (if (= c (1- n-players))
              0
            (1+ c)))))

愚痴#0: どうして nth と elt は引数の順番が違うんだぜ?

愚痴#1: replace-nth を作るのに小一時間かかった。replace-nth なんて作らないで append と subseq で済ませばいーのに、と書いてみたら1分かからなかった。とてもしょんぼり。

(defun rnth (seq index new)
  (append (subseq seq 0 (1- index))
          (list new)
          (subseq seq index)))