Guest User

Untitled

a guest
May 18th, 2018
162
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lisp 2.14 KB | None | 0 0
  1. (defun isOut(X)
  2.    (cond
  3.       ((and (< 0 (car X))
  4.  (> MAXCOR (car X))
  5. (< 0 (cdr X)) (> MAXCOR (cdr X))) T)
  6.       (T nil)
  7.    )
  8. )
  9.  
  10. (defun isVisited(X Y)
  11.    (cond
  12.       ((null X) nil)
  13.       ((null Y) nil)
  14.       ((and (= (car X)
  15. (caar Y)) (= (cdr X)
  16. (cdar Y))) T)
  17.       (T (isVisited X
  18. (cdr Y)))
  19.    )
  20. )
  21.  
  22. (defun isCorr(From Dest)
  23.    (cond
  24.       ((equal From Dest) T)
  25.       (T nil)
  26.    )
  27. )
  28.  
  29. (defun find_path(From Visited Dest);
  30.    (cond
  31.       ((and (< 0 (length result))
  32.  (< (length result)
  33.  (length (cons from visited)))) nil)
  34.       ((or (isVisited From Visited)
  35.  (Null (isOut From))) nil)
  36.       ((isCorr From Dest)
  37.          (cond
  38.             ((> 1 (length result))
  39.  (setq result (cons from visited)) nil)
  40.             ((> (length result)
  41. (length (cons from visited)))
  42.  (setq result (cons from visited)) nil)
  43.             (T nil)
  44.          )
  45.       )
  46.       (T
  47.          (or
  48.             (find_path (cons (+ (car From) 1)
  49.  (+ (cdr From) 2)) (cons From Visited) Dest)
  50.             (find_path (cons (+ (car From) 1)
  51.  (- (cdr From) 2)) (cons From Visited) Dest)
  52.             (find_path (cons (- (car From) 1)
  53.  (+ (cdr From) 2)) (cons From Visited) Dest)
  54.             (find_path (cons (- (car From) 1)
  55.  (- (cdr From) 2)) (cons From Visited) Dest)
  56.             (find_path (cons (+ (car From) 2)
  57.  (+ (cdr From) 1)) (cons From Visited) Dest)
  58.             (find_path (cons (+ (car From) 2)
  59.  (- (cdr From) 1)) (cons From Visited) Dest)
  60.             (find_path (cons (- (car From) 2)
  61. (+ (cdr From) 1)) (cons From Visited) Dest)
  62.             (find_path (cons (- (car From) 2)
  63.  (- (cdr From) 1)) (cons From Visited) Dest)
  64.          )
  65.       )
  66.    )
  67. )
  68.  
  69. (defun path(From Visited Dest)
  70.    (setq result nil)
  71.    (find_path From Visited Dest)
  72.    (prnLS result)
  73.    (princ "Решение надйдено за ")
  74. (princ (- (length result) 1))(princ " шага(ов)")
  75. )
  76. (defun prnLS(list)
  77.    (cond
  78.       ((null list) 0)
  79.       (t
  80.          (prnls (cdr list))
  81.          (print (car list))
  82.       )
  83.    )
  84. )
  85. (defun sol(From To SZ)
  86.    (setq MAXCOR (+ SZ 1))
  87.    (cond
  88.       ((and (isOut From) (isOut To))
  89.  (path From '() To) (princ "\n"))
  90.    )
  91. )
Add Comment
Please, Sign In to add comment