input.scm 747 B

1234567891011121314151617181920212223242526
  1. (define-module (euler input))
  2. (define-public default-array
  3. (list->array 2
  4. (list
  5. (list 131 673 234 103 18)
  6. (list 201 96 342 965 150)
  7. (list 630 803 746 422 111)
  8. (list 537 699 497 121 956)
  9. (list 805 732 524 37 331))))
  10. (define-public (make-matrix-from-file file)
  11. (let ((port (open-input-file file)))
  12. (let loop ((line (get-line port)) (lst '()))
  13. (if (eof-object? line) (list->array 2 (reverse lst))
  14. (loop (get-line port) (cons (line->number-list line) lst))))))
  15. (define-public (line->number-list line)
  16. (map string->number (string-split line #\,)))
  17. ;; TODO: eventually move this to io module
  18. (define-public (print-array array)
  19. (for-each (lambda (row)
  20. (display row) (newline))
  21. (array->list array)))