Let's write β

プログラミング中にできたことか、思ったこととか

ICPC2004 Problem A

Hanafuda Shuffle
もちろんLisp

(defun create-deck (num)
  (loop for card from num downto 1
       collect card))
(defun cut (cards p c)
  (let
      ((head (loop for idx from 1 upto (1- p)
		collect (nth (1- idx) cards)))
       (selected (loop for idx from p upto (1- (+ p c))
		    collect (nth (1- idx) cards)))
       (tail (loop for idx from (+ p c) upto (length cards)
		collect (nth (1- idx) cards))))
    `(,@selected ,@head ,@tail)
    ))

(defun main ()
  (loop
     for n = (read)
     for deck = (create-deck n)
     for r = (read)
     until (and (zerop n) (zerop r))
     do
       (loop for i from 1 upto r
	    do
	    (setf deck (cut deck (read) (read)))
	    finally (format t "~A~%" (car deck))
	    )))