diff --git a/lib.rkt b/lib.rkt index 7c1c18e..08e63c8 100644 --- a/lib.rkt +++ b/lib.rkt @@ -20,6 +20,7 @@ vector-grid-update lists->vectors vectors->lists + lists->hash hash->vectors show-list-grid show-vector-grid @@ -122,6 +123,15 @@ (define (vectors->lists vector-grid) (map vector->list (vector->list vector-grid))) +;; lists->hash : list-grid -> hash-grid +(define (lists->hash list-grid) + (let ([width (length (first list-grid))] + [length (length list-grid)]) + (for*/fold ([hash-grid (hash)]) + ([x (in-range width)] + [y (in-range length)]) + (hash-set hash-grid (cons x y) (list-ref (list-ref list-grid y) x))))) + ;; hash->vectors : hash-grid -> number -> vector-grid ;; Where the position is not in the hash-grid, ;; the vector-grid takes on the default value. diff --git a/stats.rkt b/stats.rkt new file mode 100644 index 0000000..5004778 --- /dev/null +++ b/stats.rkt @@ -0,0 +1,26 @@ +#lang curly-fn racket + +(require threading + (only-in 2htdp/batch-io + read-lines)) + +(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 srcs + (~>> (range 1 11) + (map (λ~>> source-input + (filter non-empty-string?))))) + +(define src-lengths (map length srcs)) + +(define src-widths + (~>> srcs + (apply append) + (map string-length) + (sort _ <=))) + +(define src-widths-string + (string-join (map number->string src-widths) ","))