Data commit

This commit is contained in:
Ingy döt Net 2023-07-01 11:58:00 -04:00
parent 7387c8f97b
commit cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions

View file

@ -0,0 +1,16 @@
;; Returns a path connecting two given cells in the maze
;; find-path :: Maze Cell Cell -> (Listof Cell)
(define (find-path m p1 p2)
(match-define (maze N M tbl) m)
(define (alternatives p prev) (remove prev (connections tbl p)))
(define (dead-end? p prev) (empty? (alternatives p prev)))
(define ((next-turn route) p)
(define prev (car route))
(cond
[(equal? p p2) (cons p2 route)]
[(dead-end? p prev) '()]
[else (append-map (next-turn (cons p route))
(alternatives p prev))]))
(reverse
(append-map (next-turn (list p1))
(alternatives p1 (list p1)))))

View file

@ -0,0 +1,18 @@
;; Reads the maze from the textual form
;; read-maze :: File-path -> Maze
(define (read-maze file)
(define tbl (make-hash))
(with-input-from-file file
(λ ()
; the first line gives us the width of the maze
(define N (/ (- (string-length (read-line)) 1) 4))
; while reading other lines we get the height of the maze
(define M
(for/sum ([h (in-lines)] [v (in-lines)] [j (in-naturals)])
(for ([i (in-range N)])
(when (eq? #\space (string-ref h (* 4 (+ 1 i))))
(connect! tbl (list i j) (list (+ i 1) j)))
(when (eq? #\space (string-ref v (+ 1 (* 4 i))))
(connect! tbl (list i j) (list i (+ j 1)))))
1))
(maze N M tbl))))

View file

@ -0,0 +1,22 @@
;; Shows a maze with a path connecting two given cells
(define (show-path m p1 p2)
(match-define (maze N M tbl) m)
(define route (find-path m p1 p2))
(for ([i N]) (display "+---"))
(displayln "+")
(for ([j M])
(display "|")
(for ([i (- N 0)])
(if (member (list i j) route)
(display " *")
(display " "))
(if (connected? tbl (list i j) (list (+ 1 i) j))
(display " ")
(display " |")))
(newline)
(for ([i N])
(if (connected? tbl (list i j) (list i (+ j 1)))
(display "+ ")
(display "+---")))
(displayln "+"))
(newline))