This repository has been archived by the owner on Oct 20, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
breadth.scm
34 lines (27 loc) · 1.48 KB
/
breadth.scm
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
(define inicial '())
(define final '())
(define (breadth-first bc)
(display "Ingrese el estado inicial: ") (set! inicial (read))
(display "Ingrese el estado final: ") (set! final (read))
(cond ((equal? inicial final) (display "El problema ya esta resuelto !!!") (newline) (breadth-first bc))
(#T (buscar bc final (list (list inicial)) '()))))
(define (buscar bc fin grafobusq estexp)
(cond
((null? grafobusq) (fracaso)) ((pertenece fin (car grafobusq)) (exito grafobusq))
(#t (buscar bc fin (append (cdr grafobusq) (expandir (car grafobusq) bc estexp))
(if (pertenece (car (car grafobusq)) estexp) estexp (cons (car (car grafobusq)) estexp))))))
(define (expandir linea basecon estexp)
(if (or (null? basecon) (pertenece (car linea) estexp))
()
(if (not (equal? ((eval (car basecon)) (car linea)) (car linea)))
(cons (cons ((eval (car basecon)) (car linea)) linea) (expandir linea (cdr basecon) estexp))
(expandir linea (cdr basecon) estexp))))
(define (pertenece x lista)
(cond ((null? lista) #f) ((equal? x (car lista)) #t)
(else (pertenece x (cdr lista)))))
(define (fracaso)
(display "No existe solucion") (newline) #t)
(define (exito grafobusq)
(display "Exito !!!") (newline)
(display "Prof ....... ") (display (- (length (car grafobusq)) 1)) (newline)
(display "Solucion ... ") (display (reverse (car grafobusq))) (newline) #t)