-
Notifications
You must be signed in to change notification settings - Fork 0
/
hr_princess2.lisp
39 lines (33 loc) · 1.07 KB
/
hr_princess2.lisp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
(defun determine-princess (size)
(let* ((x nil) (y nil))
(dotimes (fy size)
(let ((fx (position #\p (read-line) :test #'equal)))
(if fx (list (setf x fx) (setf y fy)))))
(list x y)))
(defun delimiterp (c) (position c " "))
(defun my-split (string &key (delimiterp #'delimiterp))
(loop :for beg = (position-if-not delimiterp string)
:then (position-if-not delimiterp string :start (1+ end))
:for end = (and beg (position-if delimiterp string :start beg))
:when beg :collect (subseq string beg end)
:while end))
(defun decide (dx dy)
(cond
((and
(> dx 0)
(> (abs dx) (abs dy)))
:right)
((and
(< dx 0)
(> (abs dx) (abs dy)))
:left)
((> dy 0) :down)
(t :up)))
(defun rescue-princess ()
(let* ((size (parse-integer (read-line)))
(l (my-split (read-line)))
(b (list (parse-integer (second l)) (parse-integer (first l))))
(p (determine-princess size))
(v (mapcar (function -) p b)))
(princ (symbol-name (apply (function decide) v)))))
(rescue-princess)