1
0
Fork 0

Update library and stats.

This commit is contained in:
Jonathan Chan 2021-12-05 10:34:29 -08:00 committed by Jonathan Chan
parent 9bafad63d6
commit eb98a66b34
2 changed files with 14 additions and 21 deletions

13
lib.rkt
View File

@ -4,10 +4,7 @@
threading threading
(only-in data/queue (only-in data/queue
make-queue make-queue
enqueue!) enqueue!))
(only-in 2htdp/batch-io
read-lines
read-file))
(provide (all-from-out threading) (provide (all-from-out threading)
(all-defined-out)) (all-defined-out))
@ -35,15 +32,15 @@
;; Return contents of input file input/xx.txt as lines of strings. ;; Return contents of input file input/xx.txt as lines of strings.
(define (problem-input n [suffix ""]) (define (problem-input n [suffix ""])
(let* ([filename (~a n #:min-width 2 #:align 'right #:left-pad-string "0")] (let* ([filename (~a n #:min-width 2 #:align 'right #:left-pad-string "0")]
[path (string-append "../input/" filename suffix ".txt")]) [path (build-path ".." "input" (format "~a~a.txt" filename suffix))])
(read-lines path))) (file->lines path)))
;; problem-input-all : number? -> string? ;; problem-input-all : number? -> string?
;; Return contents of input file input/xx.txt as a single string. ;; Return contents of input file input/xx.txt as a single string.
(define (problem-input-all n [suffix ""]) (define (problem-input-all n [suffix ""])
(let* ([filename (~a n #:min-width 2 #:align 'right #:left-pad-string "0")] (let* ([filename (~a n #:min-width 2 #:align 'right #:left-pad-string "0")]
[path (string-append "../input/" filename suffix ".txt")]) [path (build-path ".." "input" (format "~a~a.txt" filename suffix))])
(read-file path))) (file->string path)))
;; problem-input-grouped : number? -> (listof string?) ;; problem-input-grouped : number? -> (listof string?)
;; Return contents of input file input/xx.txt as a list of strings, ;; Return contents of input file input/xx.txt as a list of strings,

View File

@ -1,24 +1,20 @@
#lang curly-fn racket #lang curly-fn racket
(require threading (require threading)
(only-in 2htdp/batch-io
read-lines))
(define (source-input n) (define rkt-files
(let* ([filename (~a n #:min-width 2 #:align 'right #:left-pad-string "0")] (filter #{regexp-match #rx".*\\.rkt$" (path->string %)}
[path (string-append "src/" filename ".rkt")]) (directory-list "src/" #:build? #{build-path "src/" %})))
(read-lines path)))
(define srcs (define srcs
(~>> (range 1 11) (map (λ~>> file->lines
(map (λ~>> source-input (filter non-empty-string?))
(filter non-empty-string?))))) rkt-files))
(define src-lengths (map length srcs)) (define src-lengths (map length srcs))
(define src-widths (define src-widths
(~>> srcs (~>> (apply append srcs)
(apply append)
(map string-length) (map string-length)
(sort _ <=))) (sort _ <=)))