From 2e4c2e3f360b987a6627462b36b60c9329f45773 Mon Sep 17 00:00:00 2001 From: Jonathan Chan Date: Sun, 5 Dec 2021 10:34:29 -0800 Subject: [PATCH] Update library and stats. --- lib.rkt | 13 +++++-------- stats.rkt | 22 +++++++++------------- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/lib.rkt b/lib.rkt index 785086e..88b06fe 100644 --- a/lib.rkt +++ b/lib.rkt @@ -4,10 +4,7 @@ threading (only-in data/queue make-queue - enqueue!) - (only-in 2htdp/batch-io - read-lines - read-file)) + enqueue!)) (provide (all-from-out threading) (all-defined-out)) @@ -35,15 +32,15 @@ ;; Return contents of input file input/xx.txt as lines of strings. (define (problem-input n [suffix ""]) (let* ([filename (~a n #:min-width 2 #:align 'right #:left-pad-string "0")] - [path (string-append "../input/" filename suffix ".txt")]) - (read-lines path))) + [path (build-path ".." "input" (format "~a~a.txt" filename suffix))]) + (file->lines path))) ;; problem-input-all : number? -> string? ;; Return contents of input file input/xx.txt as a single string. (define (problem-input-all n [suffix ""]) (let* ([filename (~a n #:min-width 2 #:align 'right #:left-pad-string "0")] - [path (string-append "../input/" filename suffix ".txt")]) - (read-file path))) + [path (build-path ".." "input" (format "~a~a.txt" filename suffix))]) + (file->string path))) ;; problem-input-grouped : number? -> (listof string?) ;; Return contents of input file input/xx.txt as a list of strings, diff --git a/stats.rkt b/stats.rkt index 5004778..d3fbcfa 100644 --- a/stats.rkt +++ b/stats.rkt @@ -1,26 +1,22 @@ #lang curly-fn racket -(require threading - (only-in 2htdp/batch-io - read-lines)) +(require threading) -(define (source-input n) - (let* ([filename (~a n #:min-width 2 #:align 'right #:left-pad-string "0")] - [path (string-append "src/" filename ".rkt")]) - (read-lines path))) +(define rkt-files + (filter #{regexp-match #rx".*\\.rkt$" (path->string %)} + (directory-list "src/" #:build? #{build-path "src/" %}))) (define srcs - (~>> (range 1 11) - (map (λ~>> source-input - (filter non-empty-string?))))) + (map (λ~>> file->lines + (filter non-empty-string?)) + rkt-files)) (define src-lengths (map length srcs)) (define src-widths - (~>> srcs - (apply append) + (~>> (apply append srcs) (map string-length) (sort _ <=))) (define src-widths-string - (string-join (map number->string src-widths) ",")) + (string-join (map number->string src-widths) ",")) \ No newline at end of file