149.scm 928 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. ;; Searching for maximum-subsequence
  2. ;; Dijkstras: find maximum path
  3. (define-module (euler p149))
  4. (use-modules (search dijkstras)
  5. (utils fold))
  6. (define (max-path-in-network network)
  7. (let [(network-copy network)]
  8. (array-fold
  9. (lambda (path max-path)
  10. (if (> path max-path) path max-path))
  11. (array-index-map! network
  12. (lambda (i j)
  13. (max-path-from network-copy i j))))))
  14. (define (min-path-from network i j)
  15. (let ([min-path-network (make-min-network network i j)])
  16. (get-max-path min-path-network)))
  17. (define (make-min-path-network-from network i j)
  18. 0)
  19. (define (get-min-path max-path-network)
  20. (array-fold
  21. (lambda (point acc)
  22. (if (> (vertex-dist point) (vertex-dist acc)) point acc))
  23. (array-ref max-path-network 0 0)
  24. max-path-network))
  25. (define default-array
  26. (list->array 2
  27. (list
  28. (list -2 5 3 2)
  29. (list 9 -6 5 1)
  30. (list 3 2 7 3)
  31. (list -1 8 -4 8))))