Guest User

Untitled

a guest
Apr 10th, 2012
27
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Scheme 1.43 KB | None | 0 0
  1. (define (polaczenia w)
  2.   (case w
  3.     ('s '((a . 5) (d . 4)))
  4.     ('d '((a . 5) (s . 4) (e . 1)))
  5.     ('a '((d . 5) (s . 5) (b . 3)))
  6.     ('b '((a . 3) (e . 6) (c . 2)))
  7.     ('e '((d . 1) (b . 6) (f . 2)))
  8.     ('c '((b . 2)))
  9.     ('f '((e . 2) (g . 3)))
  10.     ('g '((f . 3)))
  11.   )
  12. )
  13.  
  14. (define (wsp w)
  15.   (case w
  16.     ('s '(1 . 3))
  17.     ('a '(3 . 1))
  18.     ('d '(4 . 5))
  19.     ('b '(6 . 1))
  20.     ('e '(5 . 5))
  21.     ('f '(7 . 5))
  22.     ('c '(8 . 2))
  23.     ('g '(9 . 3))
  24.   )
  25. )
  26. (define (mapuj f a)
  27.   (if (null? a)
  28.       '()
  29.       (cons
  30.         (f (car a))
  31.         (mapuj f (cdr a))
  32.       )
  33.    )
  34. )
  35. (define (szukaj x l)
  36.   (if (null? l) #f (if (equal? x (car l)) #t (szukaj x (cdr l))))
  37. )
  38. (define (odwroc a) (odwroc_ a '()))
  39. (define (odwroc_ a b) (if (null? a) b (odwroc_ (cdr a) (cons (car a) b))))
  40. (define (SzukajWGlab start cel) (odwroc (SzukajWGlabPom cel (list start))))
  41. (define (SzukajWGlabPom cel droga)
  42.   (if (equal? (car droga) cel)
  43.     droga
  44.     (SzukajWGlabPrzez cel droga (mapuj car (polaczenia (car droga))))
  45.   )
  46. )
  47. (define (SzukajWGlabPrzez cel droga sasiedzi)
  48.   (if (null? sasiedzi)
  49.     '()
  50.     (if (szukaj (car sasiedzi) droga)
  51.           (SzukajWGlabPrzez cel droga (cdr sasiedzi))
  52.           (if (null? (SzukajWGlabPom cel (cons (car sasiedzi) droga)))
  53.              (SzukajWGlabPrzez cel droga (cdr sasiedzi))
  54.              (SzukajWGlabPom cel (cons (car sasiedzi) droga))
  55.           )
  56.        
  57.     )
  58.   )
  59. )
Advertisement
Add Comment
Please, Sign In to add comment