Update library and stats.
This commit is contained in:
parent
cb4d7a3028
commit
2e4c2e3f36
13
lib.rkt
13
lib.rkt
|
@ -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,
|
||||||
|
|
20
stats.rkt
20
stats.rkt
|
@ -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 _ <=)))
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue