#lang racket

(require graph)

;; this enables looking up the string labels when we're done
(define label-lookup (make-hash))

;; str -> (list num str str)
(define (parse-line line)
  (match-define (list from to distance label) (string-split line " "))
  (hash-set! label-lookup (list from to) label)
  (hash-set! label-lookup (list to from) label)
  (list (string->number distance) from to))

(displayln "reading file")
(define input
  (map parse-line (file->lines "map.txt")))

(displayln "creating graph")
(define g (weighted-graph/undirected input))

(displayln "running coding and algorithms")
(define-values [dist pred] (dijkstra g "1"))
(displayln "done")

;; prints the path in reverse order then the labels in forward order
(define (walk x)
  (displayln x)
  (define the-pred (hash-ref pred x #f))
  (unless (false? the-pred)
    (walk the-pred)
    (displayln (hash-ref label-lookup (list the-pred x)))))

(walk "200000")
