;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; ONLY implement algolythm ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; variables (defparameter *n* 12) (defparameter *primes* '()) ; functions ; create a list of prime numbers below n. (defun create-primes (n) ; create nil array, n elements (setf nums (make-array (1+ n) :initial-element t)) ; 0th, 1st is nil (setf (aref nums 0) nil) (setf (aref nums 1) nil) ; Eratosthenes (loop for i from 2 to n while (<= i (sqrt n)) do (if (equal (aref nums i) t) (loop for j from 2 to n while (<= (* i j) n) do (setf (aref nums (* i j)) nil) ) ) ) ; push the index of t (loop for flag across nums for i from 0 to n do (if (equal flag t) (push i *primes*))) (setf *primes* (reverse *primes*)) ) (defun calc-win-lose (n) (loop for i from 2 to n do (update-win-lose i)) ) (defun update-win-lose (n) (loop for i in *primes* with x = (- n 2) do (setf y (- n i)) (cond ((or (<= y 1) (< x 0)) nil) ((equal (aref *win-lose* y) nil) ; you win when you get this number (setf (aref *win-lose* n) t)) ; you lose (t nil))) ) (defun input () (setf *n* (parse-integer (read-line))) ) (defun n7 () (input) ; win-lose array ; win:t lose:nil (setf *win-lose* (make-array (1+ *n*) :initial-element nil)) (create-primes *n*) (calc-win-lose *n*) (if (aref *win-lose* *n*) (princ "Win") (princ "Lose")) ) (n7)