One Problem -- how to implement in three programming paradigms in Python

Ludger.Humbert Ludger.Humbert at cs.uni-dortmund.de
Wed Jun 18 14:56:51 EDT 2003


Bengt Richter schrieb:

> OTOH, what I posted is not exactly final-draft textbook quality.
> There's some leftover cruft that doesn't need to be there, and
> some kludgy parameter passing, etc. That's the problem with posting
> the first thing that seems to work, and then noticing some warts
> (or worse, not noticing a real bug) ;-/
> 
> I don't know what you are using these things for, but they
> could benefit from some polishing and some unit tests ;-)
We'll use it in our introduction course didactics of informatics
for secondary II level -- for teacher training k10-k13 at german schools
-- preservice teacher training.

In the meantime a solution appeared, which was written in DrScheme, to
show a functional solution for the original problem
 http://in.hagen.de/~humbert/vortraege/F.Grundkonzepte_html/22.html

The functional style in scheme
(but I am looking for a pure functional solution in Python ;-(

(define labyrinth-small
  (list(list 'rein 28)
       (list 28 37)
       (list 37 17)
       (list 37 47)
       (list 47 46)
       (list 46 66)
       (list 46 45)
       (list 45 35)
       (list 35 25)
       (list 35 33)
       (list 33 'raus)))

(define (weg? location maze)
  (if (equal? maze empty)
      false
      (cond [(or (equal? location (first (first maze)))
                 (equal? location (rest (first maze))))
             true]
            [else (weg? location (rest maze))])))

(define (remove-location a maze)
  (if (equal? maze empty)
      empty
      (if (equal? a (first (first maze)))
          (rest maze)
          (cons (first maze) (remove-location a (rest maze))))))


(define (tour start ziel maze)
  (if (equal? start ziel)
      (display "geschafft!")
      (if (weg? start maze)
          (begin
            (display start)
            (display " ")
            (tour (first (rest (first maze)))
                  ziel
                  (remove-location start maze))
            (tour start ziel (remove-location start maze))
            )
          (display " "))))

by Athanasios Papoulias





More information about the Python-list mailing list